diff options
Diffstat (limited to '')
| -rw-r--r-- | internal/admin/service_test.go | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/internal/admin/service_test.go b/internal/admin/service_test.go index bbdab85..13a0007 100644 --- a/internal/admin/service_test.go +++ b/internal/admin/service_test.go @@ -5,7 +5,6 @@ import ( "log" "os" "path/filepath" - "strings" "testing" ) @@ -97,12 +96,16 @@ func TestInitServer(t *testing.T) { // stuff svc.Reload() // check policy file to make sure it was saved - data, err := os.ReadFile(destPolicyFile) - if err != nil { - t.Fatal(err) + expectedPolicies := [][]string{ + {"role:maintainers", "/thisismynewrepo/info/refs", "GET"}, + {"role:maintainers", "/thisismynewrepo/git-upload-pack", "POST"}, + {"role:maintainers", "/thisismynewrepo/git-receive-pack", "POST"}, } - if !strings.Contains(string(data), "thisismynewrepo") { - t.Fatal("expected to find test new repo but didn't") + for _, policy := range expectedPolicies { + if !svc.HasPolicy(policy[0], policy[1], policy[2]) { + t.Log("policy not found", policy) + t.Fail() + } } }) t.Run("test reload config err", func(t *testing.T) { @@ -121,12 +124,16 @@ func TestInitServer(t *testing.T) { // stuff svc.Reload() // check policy file to make sure it wasn't saved - data, err := os.ReadFile(destPolicyFile) - if err != nil { - log.Fatal(err) + expectedPolicies := [][]string{ + {"role:admin", "/mgmt/info/refs", "GET"}, + {"role:admin", "/mgmt/git-upload-pack", "POST"}, + {"role:admin", "/mgmt/git-receive-pack", "POST"}, } - if !strings.Contains(string(data), "mgmt") { - log.Fatal("expected to mgmt repo but didn't in policy") + for _, policy := range expectedPolicies { + if !svc.HasPolicy(policy[0], policy[1], policy[2]) { + t.Log("policy not found", policy) + t.Fail() + } } }) t.Run("test an unitialized server config", func(t *testing.T) { @@ -139,6 +146,7 @@ func TestInitServer(t *testing.T) { true) if svc.Conf.Name != "default config" { log.Fatalf("found %s expected 'default config'", svc.Conf.Name) + t.Fail() } }) } |