aboutsummaryrefslogtreecommitdiff
path: root/internal/admin
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin')
-rw-r--r--internal/admin/model.go1
-rw-r--r--internal/admin/model_test.go47
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`")
+ }
+ })
+}