From df0a52f53739a1bc05620f3f21533922488c0491 Mon Sep 17 00:00:00 2001 From: Max Resnick Date: Fri, 1 Aug 2025 22:10:20 -0700 Subject: feat: go-module support --- internal/modules/handler_test.go | 550 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 550 insertions(+) create mode 100644 internal/modules/handler_test.go (limited to 'internal/modules/handler_test.go') diff --git a/internal/modules/handler_test.go b/internal/modules/handler_test.go new file mode 100644 index 0000000..b173f98 --- /dev/null +++ b/internal/modules/handler_test.go @@ -0,0 +1,550 @@ +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, `