diff options
| author | Max Resnick <max@ofmax.li> | 2023-02-11 10:47:46 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2023-02-11 10:47:46 -0800 |
| commit | 754159c40f64478f2656b4fdef2b66c31dfe1211 (patch) | |
| tree | 36a05b05fb2f64bd49bf3e21358bc3fef9b51ba4 /internal | |
| parent | 45a8dfd3ba345eebe268fc92d31612e14907fb01 (diff) | |
| download | go-git-server-754159c40f64478f2656b4fdef2b66c31dfe1211.tar.gz | |
test repo reconcile transitions
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/admin/model_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go index 85ca8f4..a4b5874 100644 --- a/internal/admin/model_test.go +++ b/internal/admin/model_test.go @@ -4,8 +4,10 @@ import ( "errors" "fmt" "io/fs" + "io/ioutil" "os" "path/filepath" + "strings" "testing" "gopkg.in/ini.v1" @@ -76,6 +78,7 @@ func TestCasbinPolicies(t *testing.T) { func TestConfigReconcile(t *testing.T) { tempDir := t.TempDir() + defer os.RemoveAll(tempDir) // make "fake" repo testRepo := filepath.Join(tempDir, "testrepo.git") testConf := filepath.Join(testRepo, "config") @@ -141,3 +144,60 @@ func TestConfigReconcile(t *testing.T) { } }) } + +func TestRepoReconcile(t *testing.T) { + tempDir := t.TempDir() + print(tempDir) + // defer os.RemoveAll(tempDir) + repo := &GitRepo{ + Public: true, + Name: "testrepo", + GitWebConfig: &GitWeb{ + "owner", + "description", + "category", + "url", + }, + } + repoPath := filepath.Join(tempDir, repo.Name, ".git") + repo.ReconcileRepo(tempDir) + if _, err := os.Stat(repoPath); errors.Is(err, fs.ErrNotExist) { + t.Fatal("expected repo to be created, but does not exist") + } + defaultFile := []byte(` +[core] +bare = true +`) + // write the base config to repo + tempConfigFile := filepath.Join(repoPath, "config") + ioutil.WriteFile(tempConfigFile, defaultFile, 0644) + // re-reconcile + repo.ReconcileRepo(tempDir) + content, err := ioutil.ReadFile(tempConfigFile) + if err != nil { + t.Fatal(err) + } + // check if description is in the file + if !strings.Contains(string(content), "description") { + t.Fatal("expected to find 'description' in config, didn't found", string(content)) + } + gitExportMagicPath := filepath.Join(tempDir, repo.Name, ".git", GitExportMagic) + if _, err := os.Stat(gitExportMagicPath); errors.Is(err, fs.ErrNotExist) { + t.Fatal("expected git export magic to be created, but does not exist") + } + + // Test that repo is switched back to private + repo.Public = false + // re-write the base config to repo + ioutil.WriteFile(tempConfigFile, defaultFile, 0644) + // re-reconcile + repo.ReconcileRepo(tempDir) + // check if description is *NOT* in the file + if !strings.Contains(string(content), "description") { + t.Fatal("expected to *NOT* find 'description' in config, didn't found", string(content)) + } + // make sure export is removed + if _, err := os.Stat(gitExportMagicPath); !errors.Is(err, fs.ErrNotExist) { + t.Fatal("expected git export magic to not exist, but *does* exist") + } +} |