diff options
| author | Max Resnick <max@ofmax.li> | 2022-12-26 08:37:55 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2022-12-26 08:37:55 -0800 |
| commit | 0ac7b93645b169c55f9c50423fab9d4a402e9918 (patch) | |
| tree | d4ec51e99e073d294c0bee030af29b38212f8146 /internal/admin | |
| parent | ec633ec4c55f0098535d6a438e3bc4c3786ad486 (diff) | |
| download | go-git-server-0ac7b93645b169c55f9c50423fab9d4a402e9918.tar.gz | |
update tests for latest refactor
Diffstat (limited to 'internal/admin')
| -rw-r--r-- | internal/admin/model.go | 6 | ||||
| -rw-r--r-- | internal/admin/model_test.go | 47 |
2 files changed, 39 insertions, 14 deletions
diff --git a/internal/admin/model.go b/internal/admin/model.go index c0fb888..1b3da00 100644 --- a/internal/admin/model.go +++ b/internal/admin/model.go @@ -147,10 +147,9 @@ func (r *GitRepo) ReconcileRepo(basePath string) { } // ConfigureExport setup repo for sharing and configure web settings -func (r *GitRepo) ConfigureExport(basePath string) { +func (r *GitRepo) ConfigureExport(repoBase string) { // do nothing on public repos - repoBase := fmt.Sprintf("%s.git", r.Name) - okExport := filepath.Join(repoBase, r.Name, GitExportMagic) + okExport := filepath.Join(repoBase, GitExportMagic) _, err := os.Stat(okExport) // Not public but the export setting is setting exists if !r.Public && err == nil { @@ -167,7 +166,6 @@ func (r *GitRepo) ConfigureExport(basePath string) { defer f.Close() if err != nil { log.Fatalf("git-daemon-export-ok coudln't be created %s", err) - return } } diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go index 4ec1177..e8f6e33 100644 --- a/internal/admin/model_test.go +++ b/internal/admin/model_test.go @@ -1,7 +1,9 @@ package admin import ( + "errors" "fmt" + "io/fs" "os" "path/filepath" "testing" @@ -74,17 +76,21 @@ func TestCasbinPolicies(t *testing.T) { func TestConfigReconcile(t *testing.T) { tempDir := t.TempDir() - - t.Run("test add gitweb section", func(t *testing.T) { + // make "fake" repo + testRepo := filepath.Join(tempDir, "testrepo.git") + testConf := filepath.Join(testRepo, "conf") + os.Mkdir(testRepo, 0750) + f, err := os.Create(filepath.Join(testRepo, "conf")) + if err != nil { + t.Fatalf("couldn't create testdir, %s", err) + } + f.Close() + repo := &GitRepo{ + Public: true, + Name: "testrepo", + } + t.Run("test add gitweb section and remove it", func(t *testing.T) { // make "fake" repo - testRepo := filepath.Join(tempDir, "testadd.git") - testConf := filepath.Join(testRepo, "conf") - os.Mkdir(testRepo, 0750) - f, err := os.Create(filepath.Join(testRepo, "conf")) - if err != nil { - t.Fatalf("couldn't create testdir, %s", err) - } - f.Close() gw := &GitWeb{ "owner", "description", @@ -93,6 +99,9 @@ func TestConfigReconcile(t *testing.T) { } gw.ReconcileGitConf(testRepo) cfg, err := ini.Load(testConf) + if err != nil { + t.Fatalf("an error occured loading config %s", err) + } if !cfg.HasSection("gitweb") { t.Fatalf("reconciler conf didn't have a section `gitweb`") } @@ -113,4 +122,22 @@ func TestConfigReconcile(t *testing.T) { t.Fatalf("reconciler conf didn't remove section `gitweb`") } }) + t.Run("test magic export file is created", func(t *testing.T) { + exportPath := filepath.Join(testRepo, GitExportMagic) + repo.ConfigureExport(testRepo) + _, err := os.Stat(exportPath) + if errors.Is(err, fs.ErrNotExist) { + t.Fatal("expected export file to exist, but does not exist") + } + if err != nil { + t.Fatalf("encountered an error %s", err) + } + // copy repo + pvtRepo := repo + pvtRepo.Public = false + pvtRepo.ConfigureExport(testRepo) + if _, err := os.Stat(exportPath); err == nil { + t.Fatal("expected export file exist, but does not exist") + } + }) } |