aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/model_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/model_test.go')
-rw-r--r--internal/admin/model_test.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/internal/admin/model_test.go b/internal/admin/model_test.go
index 7f816f5..70ec738 100644
--- a/internal/admin/model_test.go
+++ b/internal/admin/model_test.go
@@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/fs"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -18,6 +17,7 @@ import (
"gopkg.in/ini.v1"
)
+//nolint:cyclop
func TestCasbinPolicies(t *testing.T) {
roleName := "myrole"
repoName := "myrepo"
@@ -86,7 +86,7 @@ func TestLoadServerConfig(t *testing.T) {
localDir := t.TempDir()
// TODO Refactor next touch
localFile := filepath.Join(localDir, "stuff.yaml")
- srcFile, err := os.Open("../../gitserver.yaml")
+ srcFile, err := os.Open(filepath.Clean("../../gitserver.yaml"))
if err != nil {
t.Fatalf("Error opening base config %s", err)
}
@@ -105,7 +105,7 @@ func TestLoadServerConfig(t *testing.T) {
}
// end copy file
- loadedFile, err := loadServerConfig(false, localDir, "stuff.yaml")
+ loadedFile, err := loadServerConfig(false, localDir, filepath.Join(localDir, "stuff.yaml"))
if err != nil {
t.Fatal(err)
}
@@ -114,7 +114,7 @@ func TestLoadServerConfig(t *testing.T) {
}
})
- t.Run("testing server config from git", func(t *testing.T) {
+ t.Run("testing server config from git", func(_ *testing.T) {
})
}
@@ -122,7 +122,10 @@ func TestLoadServerConfig(t *testing.T) {
func TestLocalFile(t *testing.T) {
localDir := t.TempDir()
localFile := filepath.Join(localDir, "stuff.yaml")
- os.WriteFile(localFile, []byte("stuff"), 0750)
+ //nolint:gosec
+ if err := os.WriteFile(localFile, []byte("stuff"), 0500); err != nil {
+ t.Fatal(err)
+ }
loadedFile, err := loadLocalFile(localFile)
if err != nil {
t.Fatal(err)
@@ -137,6 +140,7 @@ func TestLocalFile(t *testing.T) {
}
}
+//nolint:cyclop
func TestMgmtGitConfig(t *testing.T) {
// setup tempdir
gitDir := t.TempDir()
@@ -173,7 +177,9 @@ func TestMgmtGitConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- wt.Add(fileToCommit)
+ if _, err := wt.Add(fileToCommit); err != nil {
+ t.Fatal(err)
+ }
_, err = wt.Commit(fileToCommit, &git.CommitOptions{})
if err != nil {
t.Fatalf("Error creating commit %s", err)
@@ -203,13 +209,16 @@ func TestMgmtGitConfig(t *testing.T) {
// TODO run via serverLoadConfig
}
+//nolint:cyclop
func TestConfigReconcile(t *testing.T) {
tempDir := t.TempDir()
defer os.RemoveAll(tempDir)
// make "fake" repo
testRepo := filepath.Join(tempDir, "testrepo.git")
testConf := filepath.Join(testRepo, "config")
- os.Mkdir(testRepo, 0750)
+ 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)
@@ -247,6 +256,9 @@ func TestConfigReconcile(t *testing.T) {
emptyGitWeb := &GitWeb{}
emptyGitWeb.ReconcileGitConf(testRepo)
emptyCfg, err := ini.Load(testConf)
+ if err != nil {
+ t.Fatalf("error couldn't load %s", testConf)
+ }
if emptyCfg.HasSection("gitweb") {
t.Fatalf("reconciler conf didn't remove section `gitweb`")
}
@@ -283,15 +295,18 @@ func TestRepoReconcile(t *testing.T) {
t.Fatal("expected repo to be created, but does not exist")
}
defaultFile := []byte(`
-[core]
-bare = true
+[core]
+bare = true
`)
// write the base config to repo
tempConfigFile := filepath.Join(repoPath, "config")
- ioutil.WriteFile(tempConfigFile, defaultFile, 0644)
+ //nolint:gosec
+ if err := os.WriteFile(tempConfigFile, defaultFile, 0500); err != nil {
+ t.Fatal(err)
+ }
// re-reconcile
repo.ReconcileRepo(tempDir)
- content, err := ioutil.ReadFile(tempConfigFile)
+ content, err := os.ReadFile(tempConfigFile)
if err != nil {
t.Fatal(err)
}
@@ -303,5 +318,4 @@ bare = true
if _, err := os.Stat(gitExportMagicPath); errors.Is(err, fs.ErrNotExist) {
t.Fatal("expected git export magic to be created, but does not exist")
}
-
}