diff options
Diffstat (limited to 'internal/admin/model_test.go')
| -rw-r--r-- | internal/admin/model_test.go | 47 |
1 files changed, 37 insertions, 10 deletions
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") + } + }) } |