package modules import ( "net/http" "net/http/httptest" "strings" "testing" "git.ofmax.li/go-git-server/internal/admin" ) func TestNewModuleHandler_WithNilConfig(t *testing.T) { handler := NewModuleHandler("/tmp/repos", "example.com", nil) // Test that it returns a valid http.Handler even with nil config if handler == nil { t.Error("NewModuleHandler should return a non-nil handler") } } func TestNewModuleHandler_WithConfig(t *testing.T) { config := &admin.ServerRepos{ Repos: []*admin.GitRepo{ { Name: "mylib", GoModule: true, }, }, } handler := NewModuleHandler("/tmp/repos", "example.com", config) // Test that it returns a valid http.Handler if handler == nil { t.Error("NewModuleHandler should return a non-nil handler") } } func TestHandleGoImport_ConfiguredModule(t *testing.T) { config := &admin.ServerRepos{ Repos: []*admin.GitRepo{ { Name: "mymodule", GoModule: true, }, }, } handler := NewModuleHandler("/tmp/repos", "git.example.com", config) req := httptest.NewRequest("GET", "/mymodule?go-get=1", nil) w := httptest.NewRecorder() handler.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Errorf("expected status 200, got %d", w.Code) } body := w.Body.String() // Check for go-import meta tag if !strings.Contains(body, ``, `