aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorMax Resnick <max@ofmax.li>2024-08-16 06:41:32 -0700
committerMax Resnick <max@ofmax.li>2024-08-16 06:41:32 -0700
commit9fae69942a2b99e032b551f898785e0c380f6d7e (patch)
tree6733a678a6ad2d27f5508ecae3f2f6681518c043 /internal
parenta605348e7f3514e1803b3a26f1ef09836e1953ca (diff)
downloadgo-git-server-9fae69942a2b99e032b551f898785e0c380f6d7e.tar.gz
fix: configureexport didn't have public logic X__x
Diffstat (limited to 'internal')
-rw-r--r--internal/admin/model.go3
-rw-r--r--internal/admin/model_test.go53
2 files changed, 43 insertions, 13 deletions
diff --git a/internal/admin/model.go b/internal/admin/model.go
index a797bbd..cce61ce 100644
--- a/internal/admin/model.go
+++ b/internal/admin/model.go
@@ -276,6 +276,9 @@ func (r *GitRepo) ReconcileRepo(basePath string) error {
// ConfigureExport setup repo for sharing and configure web settings
func (r *GitRepo) ConfigureExport(repoBase string) {
+ if !r.Public {
+ return
+ }
okExport := filepath.Join(repoBase, GitWebExportMagic)
_, err := os.Create(okExport)
if err != nil {
diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go
index 9690263..b0652f2 100644
--- a/internal/admin/model_test.go
+++ b/internal/admin/model_test.go
@@ -217,24 +217,32 @@ func TestMgmtGitConfig(t *testing.T) {
//nolint:cyclop
func TestConfigReconcile(t *testing.T) {
- tempDir := t.TempDir()
+ tempDir := ""
defer os.RemoveAll(tempDir)
// make "fake" repo
- testRepo := filepath.Join(tempDir, "testrepo.git")
- testConf := filepath.Join(testRepo, "config")
- if err := os.Mkdir(testRepo, 0750); err != nil {
- t.Fatal(err)
- }
- f, err := os.Create(filepath.Join(testRepo, "config"))
- if err != nil {
- t.Fatalf("couldn't create testdir, %s", err)
- }
- f.Close()
- repo := &GitRepo{
- Name: "testrepo",
+ testRepo := ""
+ testConf := ""
+ repo := &GitRepo{}
+ configure := func() {
+ tempDir = t.TempDir()
+ testRepo = filepath.Join(tempDir, "testrepo.git")
+ testConf = filepath.Join(testRepo, "config")
+ if err := os.Mkdir(testRepo, 0750); err != nil {
+ t.Fatal(err)
+ }
+ f, err := os.Create(filepath.Join(testRepo, "config"))
+ if err != nil {
+ t.Fatalf("couldn't create testdir, %s", err)
+ }
+ f.Close()
+ repo = &GitRepo{
+ Name: "testrepo",
+ }
}
t.Run("test add gitweb section and remove it", func(t *testing.T) {
+ defer os.RemoveAll(tempDir)
// make "fake" repo
+ configure()
gw := &GitWeb{
"owner",
"description",
@@ -270,6 +278,9 @@ func TestConfigReconcile(t *testing.T) {
}
})
t.Run("test magic export file is created", func(t *testing.T) {
+ defer os.RemoveAll(tempDir)
+ configure()
+ repo.Public = true
exportPath := filepath.Join(testRepo, GitWebExportMagic)
repo.ConfigureExport(testRepo)
_, err := os.Stat(exportPath)
@@ -280,6 +291,21 @@ func TestConfigReconcile(t *testing.T) {
t.Fatalf("encountered an error %s", err)
}
})
+ t.Run("test magic export file is not created", func(t *testing.T) {
+ defer os.RemoveAll(tempDir)
+ configure()
+ exportPath := filepath.Join(testRepo, GitWebExportMagic)
+ repo.Public = false
+ repo.ConfigureExport(testRepo)
+ _, err := os.Stat(exportPath)
+ if os.IsNotExist(err) {
+ return
+ } else if err != nil {
+ t.Fatalf("encountered an error %s", err)
+ return
+ }
+ t.Fatal("expected file to not exist, but does exist")
+ })
}
func TestRepoReconcile(t *testing.T) {
@@ -294,6 +320,7 @@ func TestRepoReconcile(t *testing.T) {
"category",
"url",
},
+ Public: true,
}
repoPath := filepath.Join(tempDir, fmt.Sprintf("%s.git", repo.Name))
_ = repo.ReconcileRepo(tempDir)