diff options
| author | Max Resnick <max@ofmax.li> | 2025-05-26 00:48:20 -0700 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2025-05-26 00:49:44 -0700 |
| commit | a146f39ed183f9957f659505b74782a84e5183c0 (patch) | |
| tree | 7f62caa67c064174dca3f6879e6dfba3a0cb0b30 | |
| parent | e7a9aada4d56605677ab873f0a3090ff80e8455a (diff) | |
| download | go-git-server-a146f39ed183f9957f659505b74782a84e5183c0.tar.gz | |
fix: make sure basePath is set if it's a fresh install
| -rw-r--r-- | internal/admin/model.go | 1 | ||||
| -rw-r--r-- | internal/admin/model_test.go | 4 | ||||
| -rw-r--r-- | internal/admin/service.go | 1 | ||||
| -rw-r--r-- | internal/admin/service_test.go | 21 |
4 files changed, 27 insertions, 0 deletions
diff --git a/internal/admin/model.go b/internal/admin/model.go index 84b3c89..25262de 100644 --- a/internal/admin/model.go +++ b/internal/admin/model.go @@ -102,6 +102,7 @@ func loadConfigFromGit(baseDir, filePath string) ([]byte, error) { slog.Info("loading server config", "configPath", mgmtPath) _, err := os.Stat(mgmtPath) if errors.Is(err, os.ErrNotExist) { + slog.Info("mgmt repo not found", "path", mgmtPath) return []byte(""), ErrMgmtRepoNotFound } else if err != nil { log.Fatalf("An unexpected error was encountered %s", err) diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go index 5317335..0453d84 100644 --- a/internal/admin/model_test.go +++ b/internal/admin/model_test.go @@ -233,6 +233,10 @@ func TestMgmtGitConfig(t *testing.T) { if err == nil { t.Fatal("expected an cloning repo didn't find one") } + if !errors.Is(err, ErrMgmtRepoNotFound) { + t.Fatalf("expected ErrMgmtRepoNotFound, got %v", err) + } + // check couldnt open file err _, err = loadConfigFromGit(gitDir, "dne.yaml") if err == nil { diff --git a/internal/admin/service.go b/internal/admin/service.go index 6c969ef..ba8fe8b 100644 --- a/internal/admin/service.go +++ b/internal/admin/service.go @@ -93,6 +93,7 @@ func NewService(modelPath, policyPath, serverConfigPath, reposDir string, mgmtRe if errors.Is(err, ErrMgmtRepoNotFound) { slog.Info("no server config found, using default") conf = defaultServerConfig + conf.basePath = reposDir } else if err != nil { return &Servicer{}, fmt.Errorf("Coudln't load server config. %w", err) diff --git a/internal/admin/service_test.go b/internal/admin/service_test.go index 9af6bb9..2cf4e0d 100644 --- a/internal/admin/service_test.go +++ b/internal/admin/service_test.go @@ -88,6 +88,27 @@ func TestInitServer(t *testing.T) { destModelFile, destPolicyFile, destConfigFile := tempModelPolicyConfig(t, tempDir, tempRepoDir) + t.Run("test default config basePath", func(t *testing.T) { + // Create a new temporary directory for this test + testRepoDir := t.TempDir() + + // Create a service with mgmtRepo=true to trigger the default config path + svc, err := NewService(destModelFile, + destPolicyFile, + "gitserver.yaml", // Non-existent file to trigger default config + testRepoDir, + true) + + if err != nil { + t.Fatalf("Failed to create service: %v", err) + } + + // Verify that basePath was correctly set in the default config + if svc.Conf.basePath != testRepoDir { + t.Errorf("Expected basePath to be %q, got %q", testRepoDir, svc.Conf.basePath) + } + }) + t.Run("test reload config success", func(t *testing.T) { svc, _ := NewService(destModelFile, destPolicyFile, |