package monitor import ( "net/http" "net/http/httptest" "testing" "code.tczkiot.com/wlw/taskq/x/inspector" ) func TestNewValidatesOptions(t *testing.T) { _, err := New(Options{}) if err == nil { t.Fatalf("expected error when options missing") } // valid case ins := &inspector.Inspector{} m, err := New(Options{Inspector: ins, Queues: map[string]int{"default": 1}}) if err != nil { t.Fatalf("unexpected error: %v", err) } if m.RootPath() != "/monitor" { t.Fatalf("unexpected root path: %s", m.RootPath()) } } func TestHandleIndexServesUI(t *testing.T) { ins := &inspector.Inspector{} m, err := New(Options{Inspector: ins, Queues: map[string]int{"default": 1}, RootPath: "/my"}) if err != nil { t.Fatalf("unexpected error: %v", err) } req := httptest.NewRequest(http.MethodGet, "/my/", nil) w := httptest.NewRecorder() m.ServeHTTP(w, req) resp := w.Result() if resp.StatusCode != http.StatusOK { t.Fatalf("expected 200 OK, got %d", resp.StatusCode) } // body should contain the root path replacement body := w.Body.String() if body == "" { t.Fatalf("expected non-empty index body") } }