Skip to content

Commit

Permalink
add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
koba1t committed Aug 28, 2022
1 parent 3f0c213 commit b4d25b1
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions kustomize/commands/edit/fix/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
testutils_test "sigs.k8s.io/kustomize/kustomize/v4/commands/internal/testutils"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
Expand Down Expand Up @@ -187,6 +188,65 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: deploy.yml
`,
},
{
name: "Test fix outdated patchesStrategicMerge from a file and one string literal",
input: `
patchesStrategicMerge:
- deploy.yaml
- |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
env:
- name: CONFIG_FILE_PATH
value: home.yaml
`,
expected: `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: deploy.yaml
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
env:
- name: CONFIG_FILE_PATH
value: home.yaml
`,
},
{
name: "Test fix outdated patchesStrategicMerge and patchesJson6902",
input: `
patchesStrategicMerge:
- deploy.yaml
patchesJson6902:
- path: patch1.yaml
target:
kind: Deployment
`,
expected: `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: patch1.yaml
target:
kind: Deployment
- path: deploy.yaml
`,
},
{
Expand Down Expand Up @@ -251,12 +311,12 @@ kind: Kustomization
fSys := filesys.MakeFsInMemory()
testutils_test.WriteTestKustomizationWith(fSys, []byte(test.input))
cmd := NewCmdFix(fSys, os.Stdout)
assert.NoError(t, cmd.RunE(cmd, nil))
require.NoError(t, cmd.RunE(cmd, nil))

content, err := testutils_test.ReadTestKustomization(fSys)
assert.NoError(t, err)
assert.Contains(t, string(content), "apiVersion: ")
assert.Contains(t, string(content), "kind: Kustomization")
require.NoError(t, err)
require.Contains(t, string(content), "apiVersion: ")
require.Contains(t, string(content), "kind: Kustomization")

if diff := cmp.Diff([]byte(test.expected), content); diff != "" {
t.Errorf("%s: Mismatch (-expected, +actual):\n%s", test.name, diff)
Expand Down

0 comments on commit b4d25b1

Please sign in to comment.