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 - bodyclose
- deadcode - deadcode
- depguard - depguard
# - dogsled - dogsled
- dupl - dupl
# - errcheck # - errcheck
- exportloopref
# - funlen # - funlen
# - gochecknoinits - gochecknoinits
# - goconst - goconst
# - gocritic - gocritic
# - gocyclo - gocyclo
- gofmt - gofmt
- goimports - goimports
# - gosec - gosec
- gosimple - gosimple
- govet - govet
- ineffassign - ineffassign
# - lll - lll
- misspell - misspell
- nakedret - nakedret
- nolintlint
- revive - revive
# - scopelint
- staticcheck - staticcheck
- structcheck - structcheck
# - stylecheck # - stylecheck # seems redundant with revive, which replaced golint
- typecheck - typecheck
- unconvert - unconvert
# - unparam - unparam
- unused - unused
- varcheck - varcheck
# - whitespace - whitespace
linters-settings: linters-settings:
dupl: dupl:
@@ -49,4 +49,18 @@ linters-settings:
line-length: 170 line-length: 170
gocyclo: gocyclo:
min-complexity: 30 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 lint: $(GOBIN)/golangci-lint
$(GOBIN)/golangci-lint \ $(GOBIN)/golangci-lint \
--skip-dirs $(k8sGenDir) \ --skip-dirs $(k8sGenDir) \
run ./... run ./... \
--path-prefix=cmd/config
license: $(GOBIN)/addlicense license: $(GOBIN)/addlicense
$(GOBIN)/addlicense \ $(GOBIN)/addlicense \

View File

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

View File

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

View File

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

View File

@@ -753,12 +753,12 @@ spec:
t.FailNow() t.FailNow()
} }
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1) expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1) expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
// normalize path format for windows // normalize path format for windows
actualNormalized := strings.Replace( actualNormalized := strings.ReplaceAll(
strings.Replace(out.String(), "\\", "/", -1), strings.ReplaceAll(out.String(), "\\", "/"),
"//", "/", -1) "//", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) { if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow() 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 // normalize path format for windows
actualNormalized := strings.Replace( actualNormalized := strings.ReplaceAll(
strings.Replace(actual.String(), "\\", "/", -1), strings.ReplaceAll(actual.String(), "\\", "/"),
"//", "/", -1) "//", "/")
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1) expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
expectedNormalized := strings.Replace(expected, "\\", "/", -1) expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
if !assert.Contains(t, actualNormalized, expectedNormalized) { if !assert.Contains(t, actualNormalized, expectedNormalized) {
t.FailNow() t.FailNow()
} }

View File

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

View File

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

View File

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

View File

@@ -523,7 +523,7 @@ test/testdata/dataset-with-setters/mysql/
} }
// normalize path format for windows // 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)) { if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(test.expected)) {
t.FailNow() t.FailNow()

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,9 +17,13 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var code int
func() {
d := build() d := build()
defer os.RemoveAll(d) defer os.RemoveAll(d)
os.Exit(m.Run()) code = m.Run()
}()
os.Exit(code)
} }
type test struct { 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 { func (r *FmtRunner) runE(c *cobra.Command, args []string) error {
// format stdin if there are no args // format stdin if there are no args
if len(args) == 0 { if len(args) == 0 {
rw := &kio.ByteReadWriter{ rw := &kio.ByteReadWriter{

View File

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

View File

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

View File

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

View File

@@ -61,13 +61,13 @@ spec:
return return
} }
expected_dir, err := ioutil.TempDir("", "test-data-expected") expectedDir, err := ioutil.TempDir("", "test-data-expected")
defer os.RemoveAll(expected_dir) defer os.RemoveAll(expectedDir)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return 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 kind: Deployment
metadata: metadata:
name: app name: app
@@ -111,13 +111,13 @@ spec:
return return
} }
updated_dir, err := ioutil.TempDir("", "test-data-updated") updatedDir, err := ioutil.TempDir("", "test-data-updated")
defer os.RemoveAll(updated_dir) defer os.RemoveAll(updatedDir)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return 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 kind: Deployment
metadata: metadata:
name: app name: app
@@ -158,13 +158,13 @@ spec:
return return
} }
dest_dir, err := ioutil.TempDir("", "test-data-dest") destDir, err := ioutil.TempDir("", "test-data-dest")
defer os.RemoveAll(dest_dir) defer os.RemoveAll(destDir)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return 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 kind: Deployment
metadata: metadata:
name: app name: app
@@ -212,15 +212,15 @@ spec:
"--ancestor", "--ancestor",
datadir, datadir,
"--from", "--from",
updated_dir, updatedDir,
"--to", "--to",
dest_dir, destDir,
}) })
if !assert.NoError(t, r.Command.Execute()) { if !assert.NoError(t, r.Command.Execute()) {
return return
} }
diffs, err := copyutil.Diff(dest_dir, expected_dir) diffs, err := copyutil.Diff(destDir, expectedDir)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
t.FailNow() t.FailNow()
} }

View File

@@ -47,7 +47,8 @@ func GetRunFnRunner(name string) *RunFnRunner {
"run this image as a function instead of discovering them.") "run this image as a function instead of discovering them.")
// NOTE: exec plugins execute arbitrary code -- never change the default value of this flag!!! // NOTE: exec plugins execute arbitrary code -- never change the default value of this flag!!!
r.Command.Flags().BoolVar( 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.Command.Flags().StringVar(
&r.ExecPath, "exec-path", "", "run an executable as a function. (Alpha)") &r.ExecPath, "exec-path", "", "run an executable as a function. (Alpha)")
r.Command.Flags().BoolVar( r.Command.Flags().BoolVar(

View File

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

View File

@@ -202,8 +202,22 @@ func TestSourceCommandJSON(t *testing.T) {
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
kind: ResourceList kind: ResourceList
items: 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}} - {"kind": "Deployment", `+
- {"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}} `"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()) { `, b.String()) {
return return
} }
@@ -312,7 +326,14 @@ func TestSourceCommandJSON_Stdin(t *testing.T) {
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1 if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
kind: ResourceList kind: ResourceList
items: 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()) { `, out.String()) {
return return
} }

View File

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