Skip to content

Commit

Permalink
fix: use filepath.Join instead of "/"
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Mar 26, 2023
1 parent c53a3d3 commit 0476dcb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/policy/config_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func configFileNames() []string {
return []string{
"aqua-policy.yaml",
".aqua-policy.yaml",
"aqua/aqua-policy.yaml",
".aqua/aqua-policy.yaml",
filepath.Join("aqua", "aqua-policy.yaml"),
filepath.Join(".aqua", "aqua-policy.yaml"),
}
}

Expand Down
85 changes: 85 additions & 0 deletions pkg/policy/config_finder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package policy_test

import (
"testing"

"github.com/aquaproj/aqua/v2/pkg/policy"
"github.com/aquaproj/aqua/v2/pkg/util"
"github.com/spf13/afero"
)

func TestConfigFinderImpl_Find(t *testing.T) { //nolint:funlen
t.Parallel()
data := []struct {
name string
wd string
configFilePath string
exp string
files map[string]string
dirs map[string]struct{}
isErr bool
}{
{
name: "not found",
wd: "/home/foo/bar",
files: map[string]string{
"/home/foo/.git": "",
},
},
{
name: ".git not found",
wd: "/home/foo",
},
{
name: "configFilePath",
wd: "/home/foo",
configFilePath: "/home/foo/bar/aqua-policy.yaml",
exp: "/home/foo/bar/aqua-policy.yaml",
files: map[string]string{
"/home/foo/bar/aqua-policy.yaml": "",
},
},
{
name: "find",
wd: "/home/foo/bar",
files: map[string]string{
"/home/foo/aqua/aqua-policy.yaml": "",
},
dirs: map[string]struct{}{
"/home/foo/.git": {},
},
exp: "/home/foo/aqua/aqua-policy.yaml",
},
}
for _, d := range data {
d := d
t.Run(d.name, func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
for name, body := range d.files {
if err := afero.WriteFile(fs, name, []byte(body), 0o644); err != nil {
t.Fatal(err)
}
}
for name := range d.dirs {
if err := util.MkdirAll(fs, name); err != nil {
t.Fatal(err)
}
}
configFinder := policy.NewConfigFinder(fs)
p, err := configFinder.Find(d.configFilePath, d.wd)
if err != nil {
if d.isErr {
return
}
t.Fatal(err)
}
if d.isErr {
t.Fatal("error must be returend")
}
if p != d.exp {
t.Fatalf("wanted %v, got %v", d.exp, p)
}
})
}
}

0 comments on commit 0476dcb

Please sign in to comment.