diff options
| author | Max Resnick <max@ofmax.li> | 2022-12-17 23:45:40 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2022-12-17 23:48:30 -0800 |
| commit | ec633ec4c55f0098535d6a438e3bc4c3786ad486 (patch) | |
| tree | 80eb05d0421f3042e7db718b2a412d3a774bf530 /internal | |
| parent | ab38860d69c194969bea9ae5ef385c35eb94b988 (diff) | |
| download | go-git-server-ec633ec4c55f0098535d6a438e3bc4c3786ad486.tar.gz | |
add more test to cover reconciler
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/admin/model.go | 1 | ||||
| -rw-r--r-- | internal/admin/model_test.go | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/internal/admin/model.go b/internal/admin/model.go index 59f2498..c0fb888 100644 --- a/internal/admin/model.go +++ b/internal/admin/model.go @@ -182,6 +182,7 @@ func (r *GitWeb) ReconcileGitConf(repoBase string) { if (GitWeb{} == *r) { if cfg.HasSection("gitweb") { cfg.DeleteSection("gitweb") + cfg.SaveTo(confPath) } return } diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go index b13bfad..4ec1177 100644 --- a/internal/admin/model_test.go +++ b/internal/admin/model_test.go @@ -2,7 +2,11 @@ package admin import ( "fmt" + "os" + "path/filepath" "testing" + + "gopkg.in/ini.v1" ) func TestCasbinPolicies(t *testing.T) { @@ -67,3 +71,46 @@ 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, "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", + "category", + "url", + } + gw.ReconcileGitConf(testRepo) + cfg, err := ini.Load(testConf) + if !cfg.HasSection("gitweb") { + t.Fatalf("reconciler conf didn't have a section `gitweb`") + } + section := cfg.Section("gitweb") + + for _, v := range []string{"owner", "description", "category", "url"} { + val := section.Key(v).Value() + if val != v { + t.Fatalf("expected %s found %s", v, val) + } + } + + // flip public repo status + emptyGitWeb := &GitWeb{} + emptyGitWeb.ReconcileGitConf(testRepo) + emptyCfg, err := ini.Load(testConf) + if emptyCfg.HasSection("gitweb") { + t.Fatalf("reconciler conf didn't remove section `gitweb`") + } + }) +} |