Add end-to-end smoke driving the real CLI against the containerized fake

This commit is contained in:
2026-08-29 06:58:35 -05:00
parent d98f0aeb93
commit bbd85fae71
4 changed files with 211 additions and 12 deletions
+14
View File
@@ -53,6 +53,20 @@ func Run(args []string, stdout, stderr io.Writer) int {
fmt.Fprint(stderr, usage)
return 1
}
// Hoist a leading global --config PATH onto the subcommand (the
// subcommand flag sets already accept it anywhere).
var hoisted []string
for len(args) >= 2 && (args[0] == "--config" || args[0] == "-config") {
hoisted = append(hoisted, args[0], args[1])
args = args[2:]
}
if len(hoisted) > 0 {
if len(args) == 0 {
fmt.Fprint(stderr, usage)
return 1
}
args = append(args, hoisted...)
}
switch args[0] {
case "help", "-h", "--help":
fmt.Fprint(stdout, usage)
+25 -12
View File
@@ -126,14 +126,32 @@ type Status struct {
// New starts a fake on a random port with Redmine's default
// enumerations and an empty MOPAC project.
func New(apiKey string) *Server {
s := &Server{
APIKey: apiKey,
apiKeySet: true,
issues: map[int]*Issue{},
versions: map[int]Version{},
s := newServer(apiKey)
mux := http.NewServeMux()
mux.HandleFunc("/", s.handler)
s.srv = httptest.NewServer(mux)
s.URL = s.srv.URL
return s
}
// ListenAndServe runs the fake on a fixed address (the smoke run boots it
// in a container). An empty apiKey disables auth checking.
func ListenAndServe(addr, apiKey string) error {
s := newServer(apiKey)
mux := http.NewServeMux()
mux.HandleFunc("/", s.handler)
return http.ListenAndServe(addr, mux)
}
func newServer(apiKey string) *Server {
return &Server{
APIKey: apiKey,
apiKeySet: true,
issues: map[int]*Issue{},
versions: map[int]Version{},
categories: map[int]Category{},
relations: map[int]Relation{},
nextID: 100,
relations: map[int]Relation{},
nextID: 100,
Trackers: []IDName{
{1, "Bug"}, {2, "Feature"}, {3, "Support"}, {4, "Task"},
},
@@ -145,11 +163,6 @@ func New(apiKey string) *Server {
{1, "Low"}, {2, "Normal"}, {3, "High"}, {4, "Urgent"}, {5, "Immediate"},
},
}
mux := http.NewServeMux()
mux.HandleFunc("/", s.handler)
s.srv = httptest.NewServer(mux)
s.URL = s.srv.URL
return s
}
// Close shuts the fake down.