aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/model_test.go
diff options
context:
space:
mode:
authorMax Resnick <max@ofmax.li>2022-12-26 08:37:55 -0800
committerMax Resnick <max@ofmax.li>2022-12-26 08:37:55 -0800
commit0ac7b93645b169c55f9c50423fab9d4a402e9918 (patch)
treed4ec51e99e073d294c0bee030af29b38212f8146 /internal/admin/model_test.go
parentec633ec4c55f0098535d6a438e3bc4c3786ad486 (diff)
downloadgo-git-server-0ac7b93645b169c55f9c50423fab9d4a402e9918.tar.gz
update tests for latest refactor
Diffstat (limited to '')
-rw-r--r--internal/admin/model_test.go47
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")
+ }
+ })
}