cmd/config linter updates

This commit is contained in:
Katrina Verey
2022-03-29 18:50:40 -04:00
parent 1567b96ed3
commit ff4136b1a2
24 changed files with 178 additions and 138 deletions

View File

@@ -12,35 +12,35 @@ linters:
- bodyclose
- deadcode
- depguard
# - dogsled
- dogsled
- dupl
# - errcheck
- exportloopref
# - funlen
# - gochecknoinits
# - goconst
# - gocritic
# - gocyclo
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
# - gosec
- gosec
- gosimple
- govet
- ineffassign
# - lll
- lll
- misspell
- nakedret
- nolintlint
- revive
# - scopelint
- staticcheck
- structcheck
# - stylecheck
# - stylecheck # seems redundant with revive, which replaced golint
- typecheck
- unconvert
# - unparam
- unparam
- unused
- varcheck
# - whitespace
- whitespace
linters-settings:
dupl:
@@ -49,4 +49,18 @@ linters-settings:
line-length: 170
gocyclo:
min-complexity: 30
revive:
rules:
- name: var-naming
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
gosec:
config:
G306: "0644"
issues:
exclude-rules:
- linters:
- revive
text: "don't use leading"

View File

@@ -36,7 +36,8 @@ clean:
lint: $(GOBIN)/golangci-lint
$(GOBIN)/golangci-lint \
--skip-dirs $(k8sGenDir) \
run ./...
run ./... \
--path-prefix=cmd/config
license: $(GOBIN)/addlicense
$(GOBIN)/addlicense \

View File

@@ -142,7 +142,6 @@ func (r *AnnotateRunner) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return nil, err
}
}
}
return nodes, nil
}

View File

@@ -601,12 +601,12 @@ added annotations in the package
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow()
}

View File

@@ -654,12 +654,12 @@ spec:
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}

View File

@@ -753,12 +753,12 @@ spec:
t.FailNow()
}
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(out.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(out.String(), "\\", "/"),
"//", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow()
@@ -863,12 +863,12 @@ setter with name "namespace" already exists, if you want to modify it, please de
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow()
}

View File

@@ -393,12 +393,12 @@ spec:
t.FailNow()
}
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(out.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(out.String(), "\\", "/"),
"//", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow()
@@ -500,12 +500,12 @@ created substitution "image-tag"`,
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
t.FailNow()
}

View File

@@ -340,12 +340,12 @@ kind: Deployment
}
// normalize path format for windows
actualNorm := strings.Replace(
strings.Replace(out.String(), "\\", "/", -1),
"//", "/", -1)
actualNorm := strings.ReplaceAll(
strings.ReplaceAll(out.String(), "\\", "/"),
"//", "/")
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
if !assert.Contains(t, strings.TrimSpace(actualNorm), expectedNormalized) {
t.FailNow()
@@ -438,12 +438,12 @@ deleted setter "namespace"
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}

View File

@@ -467,11 +467,11 @@ spec:
}
// normalize path format for windows
actualNorm := strings.Replace(
strings.Replace(out.String(), "\\", "/", -1),
"//", "/", -1)
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
expectedNorm := strings.Replace(expectedOut, "\\", "/", -1)
actualNorm := strings.ReplaceAll(
strings.ReplaceAll(out.String(), "\\", "/"),
"//", "/")
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
expectedNorm := strings.ReplaceAll(expectedOut, "\\", "/")
if !assert.Contains(t, strings.TrimSpace(actualNorm), expectedNorm) {
t.FailNow()
@@ -555,12 +555,12 @@ deleted substitution "image-tag"
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}

View File

@@ -523,7 +523,7 @@ test/testdata/dataset-with-setters/mysql/
}
// normalize path format for windows
actualNormalized := strings.Replace(actual.String(), "\\", "/", -1)
actualNormalized := strings.ReplaceAll(actual.String(), "\\", "/")
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(test.expected)) {
t.FailNow()

View File

@@ -1129,14 +1129,14 @@ set 1 field(s) of setter "namespace" to value "otherspace"
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(
strings.Replace(expected, "\\", "/", -1),
"//", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(
strings.ReplaceAll(expected, "\\", "/"),
"//", "/")
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
t.FailNow()
}

View File

@@ -106,7 +106,7 @@ func (r *XArgsRunner) runE(c *cobra.Command, _ []string) error {
return fmt.Errorf("must specify -- before command")
}
r.Args = r.Args[cmdIndex:]
run := exec.Command(r.Args[0])
run := exec.Command(r.Args[0]) // nolint: gosec
if len(r.Args) > 1 {
r.Args = r.Args[cmdIndex+1:]

View File

@@ -137,12 +137,12 @@ Deployment: 1
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}

View File

@@ -35,7 +35,7 @@ func TestRunE2e(t *testing.T) {
name: "exec_function_no_args",
args: func(d string) []string {
return []string{
"--enable-exec", "--exec-path", filepath.Join(d, "e2econtainerconfig"),
"--enable-exec", "--exec-path", filepath.Join(d, e2eConfigDir),
}
},
files: func(d string) map[string]string {
@@ -720,7 +720,7 @@ metadata:
}
args := append([]string{"fn", "run", "."}, tt.args(binDir)...)
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...)
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) // nolint: gosec
cmd.Dir = dir
var stdErr, stdOut bytes.Buffer
cmd.Stdout = &stdOut
@@ -751,6 +751,8 @@ metadata:
var buildOnce sync.Once
var binDir string
const e2eConfigDir = "e2econtainerconfig"
func build() string {
// only build the binaries once
buildOnce.Do(func() {
@@ -760,7 +762,7 @@ func build() string {
panic(err)
}
build := exec.Command("go", "build", "-o",
build := exec.Command("go", "build", "-o", // nolint: gosec
filepath.Join(binDir, e2econtainerconfigBin))
build.Dir = "e2econtainerconfig"
build.Stdout = os.Stdout
@@ -772,7 +774,7 @@ func build() string {
panic(err)
}
build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin))
build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin)) // nolint: gosec
build.Dir = filepath.Join("..", "..", "..", "kubectl-krm")
build.Stdout = os.Stdout
build.Stderr = os.Stderr
@@ -786,7 +788,7 @@ func build() string {
}
build = exec.Command(
"docker", "build", ".", "-t", "gcr.io/kustomize-functions/e2econtainerconfig")
build.Dir = "e2econtainerconfig"
build.Dir = e2eConfigDir
build.Stdout = os.Stdout
build.Stderr = os.Stderr
err = build.Run()
@@ -803,9 +805,9 @@ var (
kyamlBin string
)
func init() {
func init() { //nolint: gochecknoinits
kyamlBin = "kubectl-krm"
e2econtainerconfigBin = "e2econtainerconfig"
e2econtainerconfigBin = e2eConfigDir
if runtime.GOOS == "windows" {
kyamlBin = "kubectl-krm.exe"

View File

@@ -17,9 +17,13 @@ import (
)
func TestMain(m *testing.M) {
var code int
func() {
d := build()
defer os.RemoveAll(d)
os.Exit(m.Run())
code = m.Run()
}()
os.Exit(code)
}
type test struct {

View File

@@ -69,7 +69,6 @@ func (r *FmtRunner) preRunE(c *cobra.Command, args []string) error {
}
func (r *FmtRunner) runE(c *cobra.Command, args []string) error {
// format stdin if there are no args
if len(args) == 0 {
rw := &kio.ByteReadWriter{

View File

@@ -232,12 +232,12 @@ formatted resource files in the package
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
t.FailNow()
}

View File

@@ -73,19 +73,20 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
}
var last []string
if strings.Contains(parts[len(parts)-1], ">=") {
switch {
case strings.Contains(parts[len(parts)-1], ">="):
last = strings.Split(parts[len(parts)-1], ">=")
r.MatchType = filters.GreaterThanEq
} else if strings.Contains(parts[len(parts)-1], "<=") {
case strings.Contains(parts[len(parts)-1], "<="):
last = strings.Split(parts[len(parts)-1], "<=")
r.MatchType = filters.LessThanEq
} else if strings.Contains(parts[len(parts)-1], ">") {
case strings.Contains(parts[len(parts)-1], ">"):
last = strings.Split(parts[len(parts)-1], ">")
r.MatchType = filters.GreaterThan
} else if strings.Contains(parts[len(parts)-1], "<") {
case strings.Contains(parts[len(parts)-1], "<"):
last = strings.Split(parts[len(parts)-1], "<")
r.MatchType = filters.LessThan
} else {
default:
last = strings.Split(parts[len(parts)-1], "=")
r.MatchType = filters.Regexp
}
@@ -99,7 +100,7 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
r.Value = last[1]
}
r.Path = append(parts[:len(parts)-1], last[0])
r.Path = append(parts[:len(parts)-1], last[0]) // nolint:gocritic
return nil
}
@@ -136,7 +137,6 @@ func (r *GrepRunner) runE(c *cobra.Command, args []string) error {
fmt.Fprintf(c.OutOrStdout(), "%s", res)
return nil
}
func (r *GrepRunner) ExecuteCmd(w io.Writer, pkgPath string) error {

View File

@@ -416,12 +416,12 @@ spec:
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}

View File

@@ -61,13 +61,13 @@ spec:
return
}
expected_dir, err := ioutil.TempDir("", "test-data-expected")
defer os.RemoveAll(expected_dir)
expectedDir, err := ioutil.TempDir("", "test-data-expected")
defer os.RemoveAll(expectedDir)
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
err = ioutil.WriteFile(filepath.Join(expectedDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: app
@@ -111,13 +111,13 @@ spec:
return
}
updated_dir, err := ioutil.TempDir("", "test-data-updated")
defer os.RemoveAll(updated_dir)
updatedDir, err := ioutil.TempDir("", "test-data-updated")
defer os.RemoveAll(updatedDir)
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
err = ioutil.WriteFile(filepath.Join(updatedDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: app
@@ -158,13 +158,13 @@ spec:
return
}
dest_dir, err := ioutil.TempDir("", "test-data-dest")
defer os.RemoveAll(dest_dir)
destDir, err := ioutil.TempDir("", "test-data-dest")
defer os.RemoveAll(destDir)
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
err = ioutil.WriteFile(filepath.Join(destDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: app
@@ -212,15 +212,15 @@ spec:
"--ancestor",
datadir,
"--from",
updated_dir,
updatedDir,
"--to",
dest_dir,
destDir,
})
if !assert.NoError(t, r.Command.Execute()) {
return
}
diffs, err := copyutil.Diff(dest_dir, expected_dir)
diffs, err := copyutil.Diff(destDir, expectedDir)
if !assert.NoError(t, err) {
t.FailNow()
}

View File

@@ -47,7 +47,8 @@ func GetRunFnRunner(name string) *RunFnRunner {
"run this image as a function instead of discovering them.")
// NOTE: exec plugins execute arbitrary code -- never change the default value of this flag!!!
r.Command.Flags().BoolVar(
&r.EnableExec, "enable-exec", false /*do not change!*/, "enable support for exec functions -- note: exec functions run arbitrary code -- do not use for untrusted configs!!! (Alpha)")
&r.EnableExec, "enable-exec", false, /*do not change!*/
"enable support for exec functions -- note: exec functions run arbitrary code -- do not use for untrusted configs!!! (Alpha)")
r.Command.Flags().StringVar(
&r.ExecPath, "exec-path", "", "run an executable as a function. (Alpha)")
r.Command.Flags().BoolVar(

View File

@@ -412,7 +412,6 @@ apiVersion: v1
t.FailNow()
}
}
})
}
}

View File

@@ -202,8 +202,22 @@ func TestSourceCommandJSON(t *testing.T) {
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
kind: ResourceList
items:
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f1.json'}}, "spec": {"replicas": 1}}
- {"apiVersion": "v1", "kind": "Abstraction", "metadata": {"name": "foo", "annotations": {"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", "config.kubernetes.io/local-config": "true", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f2.json'}}, "spec": {"replicas": 3}}
- {"kind": "Deployment", `+
`"metadata": {`+
`"labels": {"app": "nginx2"}, `+
`"name": "foo", `+
`"annotations": {`+
`"app": "nginx2", `+
`config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f1.json'}}, `+
`"spec": {"replicas": 1}}
- {"apiVersion": "v1", "kind": "Abstraction", `+
`"metadata": {`+
`"name": "foo", `+
`"annotations": {`+
`"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", `+
`"config.kubernetes.io/local-config": "true", `+
`config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f2.json'}}, `+
`"spec": {"replicas": 3}}
`, b.String()) {
return
}
@@ -312,7 +326,14 @@ func TestSourceCommandJSON_Stdin(t *testing.T) {
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
kind: ResourceList
items:
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}, "spec": {"replicas": 1}}
- {"kind": "Deployment", `+
`"metadata": {`+
`"labels": {"app": "nginx2"}, `+
`"name": "foo", `+
`"annotations": {`+
`"app": "nginx2", `+
`config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}, `+
`"spec": {"replicas": 1}}
`, out.String()) {
return
}

View File

@@ -98,14 +98,14 @@ ${baseDir}/subpkg2/subpkg3/
}
// normalize path format for windows
actualNormalized := strings.Replace(
strings.Replace(actual.String(), "\\", "/", -1),
"//", "/", -1)
actualNormalized := strings.ReplaceAll(
strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/")
expected := strings.Replace(test.expectedOut, "${baseDir}", dir+"/", -1)
expectedNormalized := strings.Replace(
strings.Replace(expected, "\\", "/", -1),
"//", "/", -1)
expected := strings.ReplaceAll(test.expectedOut, "${baseDir}", dir+"/")
expectedNormalized := strings.ReplaceAll(
strings.ReplaceAll(expected, "\\", "/"),
"//", "/")
if !assert.Equal(t, expectedNormalized, actualNormalized) {
t.FailNow()
}
@@ -141,27 +141,27 @@ func createTestDirStructure(dir string) error {
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "subpkg1", "Krmfile"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "subpkg1", "Krmfile"), []byte(""), 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2", "Krmfile"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2", "Krmfile"), []byte(""), 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2/subpkg3", "Krmfile"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2/subpkg3", "Krmfile"), []byte(""), 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "error.txt"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "error.txt"), []byte(""), 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "Krmfile"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "Krmfile"), []byte(""), 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, "Krmfile"), []byte(""), 0777)
err = ioutil.WriteFile(filepath.Join(dir, "Krmfile"), []byte(""), 0644)
if err != nil {
return err
}