mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #2730 from monopole/addTest
Add a test and temporarily disable some plugin tests.
This commit is contained in:
@@ -19,3 +19,5 @@ require (
|
|||||||
sigs.k8s.io/kustomize/kyaml v0.4.1
|
sigs.k8s.io/kustomize/kyaml v0.4.1
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/kyaml v0.4.1 => ../kyaml
|
||||||
|
|||||||
@@ -580,8 +580,6 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphD
|
|||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.4.1 h1:NEqA/35upoAjb+I5vh1ODUqxoX4DOrezeQa9BhhG5Co=
|
|
||||||
sigs.k8s.io/kustomize/kyaml v0.4.1/go.mod h1:XJL84E6sOFeNrQ7CADiemc1B0EjIxHo3OhW4o1aJYNw=
|
|
||||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeCustomizedResMap creates a fully customized ResMap
|
// MakeCustomizedResMap creates a fully customized ResMap
|
||||||
// per the instructions contained in its kustomiztion instance.
|
// per the instructions contained in its kustomization instance.
|
||||||
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
||||||
return kt.makeCustomizedResMap()
|
return kt.makeCustomizedResMap()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,24 +10,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeDeployment(th *kusttest_test.HarnessEnhanced, path string) {
|
|
||||||
th.WriteF(path, `
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: myDeployment
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
backend: awesome
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: whatever
|
|
||||||
image: whatever
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeStringPrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
func writeStringPrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
||||||
th.WriteF(path, `
|
th.WriteF(path, `
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
@@ -37,53 +19,6 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeDatePrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
|
||||||
th.WriteF(path, `
|
|
||||||
apiVersion: someteam.example.com/v1
|
|
||||||
kind: DatePrefixer
|
|
||||||
metadata:
|
|
||||||
name: `+name+`
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestOrderedTransformers(t *testing.T) {
|
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
|
||||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
|
||||||
BuildGoPlugin("someteam.example.com", "v1", "DatePrefixer")
|
|
||||||
defer th.Reset()
|
|
||||||
|
|
||||||
th.WriteK("/app", `
|
|
||||||
resources:
|
|
||||||
- deployment.yaml
|
|
||||||
transformers:
|
|
||||||
- peachPrefixer.yaml
|
|
||||||
- date1Prefixer.yaml
|
|
||||||
- applePrefixer.yaml
|
|
||||||
- date2Prefixer.yaml
|
|
||||||
`)
|
|
||||||
writeDeployment(th, "/app/deployment.yaml")
|
|
||||||
writeStringPrefixer(th, "/app/applePrefixer.yaml", "apple")
|
|
||||||
writeStringPrefixer(th, "/app/peachPrefixer.yaml", "peach")
|
|
||||||
writeDatePrefixer(th, "/app/date1Prefixer.yaml", "date1")
|
|
||||||
writeDatePrefixer(th, "/app/date2Prefixer.yaml", "date2")
|
|
||||||
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
|
|
||||||
th.AssertActualEqualsExpected(m, `
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: 2018-05-11-apple-2018-05-11-peach-myDeployment
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
backend: awesome
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- image: whatever
|
|
||||||
name: whatever
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPluginsNotEnabled(t *testing.T) {
|
func TestPluginsNotEnabled(t *testing.T) {
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer")
|
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer")
|
||||||
@@ -165,6 +100,78 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
The tests below are disabled until the StringPrefixer and DatePrefixer
|
||||||
|
can be rewritten using kyaml, instead of depending on the
|
||||||
|
PrefixSuffixTransformerPlugin. That dependency is causing
|
||||||
|
failures in the test loader.
|
||||||
|
|
||||||
|
func writeDeployment(th *kusttest_test.HarnessEnhanced, path string) {
|
||||||
|
th.WriteF(path, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
backend: awesome
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: whatever
|
||||||
|
image: whatever
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeDatePrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
||||||
|
th.WriteF(path, `
|
||||||
|
apiVersion: someteam.example.com/v1
|
||||||
|
kind: DatePrefixer
|
||||||
|
metadata:
|
||||||
|
name: `+name+`
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderedTransformers(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
|
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
||||||
|
BuildGoPlugin("someteam.example.com", "v1", "DatePrefixer")
|
||||||
|
defer th.Reset()
|
||||||
|
|
||||||
|
th.WriteK("/app", `
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
transformers:
|
||||||
|
- peachPrefixer.yaml
|
||||||
|
- date1Prefixer.yaml
|
||||||
|
- applePrefixer.yaml
|
||||||
|
- date2Prefixer.yaml
|
||||||
|
`)
|
||||||
|
writeDeployment(th, "/app/deployment.yaml")
|
||||||
|
writeStringPrefixer(th, "/app/applePrefixer.yaml", "apple")
|
||||||
|
writeStringPrefixer(th, "/app/peachPrefixer.yaml", "peach")
|
||||||
|
writeDatePrefixer(th, "/app/date1Prefixer.yaml", "date1")
|
||||||
|
writeDatePrefixer(th, "/app/date2Prefixer.yaml", "date2")
|
||||||
|
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: 2018-05-11-apple-2018-05-11-peach-myDeployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
backend: awesome
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: whatever
|
||||||
|
name: whatever
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransformedTransformers(t *testing.T) {
|
func TestTransformedTransformers(t *testing.T) {
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
||||||
@@ -205,3 +212,4 @@ spec:
|
|||||||
name: whatever
|
name: whatever
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -13,6 +13,178 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSliceFromBytes(t *testing.T) {
|
||||||
|
type testCase struct {
|
||||||
|
input string
|
||||||
|
expected []string
|
||||||
|
}
|
||||||
|
testCases := map[string]testCase{
|
||||||
|
"empty1": {
|
||||||
|
input: "",
|
||||||
|
expected: []string{},
|
||||||
|
},
|
||||||
|
"empty2": {
|
||||||
|
input: `
|
||||||
|
---
|
||||||
|
---
|
||||||
|
`,
|
||||||
|
expected: []string{},
|
||||||
|
},
|
||||||
|
"deployment1": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: pooh
|
||||||
|
---
|
||||||
|
`,
|
||||||
|
expected: []string{
|
||||||
|
`apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: pooh
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"deployment2": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
name: baseprefix-mungebot
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
foo: bar
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: foo
|
||||||
|
value: bar
|
||||||
|
image: nginx
|
||||||
|
name: nginx
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
name: baseprefix-mungebot-service
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 7002
|
||||||
|
selector:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
`,
|
||||||
|
expected: []string{
|
||||||
|
`apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
name: baseprefix-mungebot
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
foo: bar
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: foo
|
||||||
|
value: bar
|
||||||
|
image: nginx
|
||||||
|
name: nginx
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
`,
|
||||||
|
`apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
baseAnno: This is a base annotation
|
||||||
|
labels:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
name: baseprefix-mungebot-service
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 7002
|
||||||
|
selector:
|
||||||
|
app: mungebot
|
||||||
|
foo: bar
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name := range testCases {
|
||||||
|
tc := testCases[name]
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
result, err := factory.SliceFromBytes([]byte(tc.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%v: fails with err: %v", name, err)
|
||||||
|
}
|
||||||
|
if len(result) != len(tc.expected) {
|
||||||
|
for i := range result {
|
||||||
|
bytes, err := result[i].AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%v: result to YAML fails with err: %v", name, err)
|
||||||
|
}
|
||||||
|
tmp := string(bytes)
|
||||||
|
t.Logf("--- %d:\n%s", i, tmp)
|
||||||
|
}
|
||||||
|
t.Fatalf(
|
||||||
|
"%v: actual len %d != expected len %d",
|
||||||
|
name, len(result), len(tc.expected))
|
||||||
|
}
|
||||||
|
for i := range tc.expected {
|
||||||
|
bytes, err := result[i].AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%v: result to YAML fails with err: %v", name, err)
|
||||||
|
}
|
||||||
|
tmp := string(bytes)
|
||||||
|
if tmp != tc.expected[i] {
|
||||||
|
t.Fatalf(
|
||||||
|
"%v: string mismatch in item %d\n"+
|
||||||
|
"actual:\n-----\n%s\n-----\n"+
|
||||||
|
"expected:\n-----\n%s\n-----\n",
|
||||||
|
name, i, tmp, tc.expected[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSliceFromPatches(t *testing.T) {
|
func TestSliceFromPatches(t *testing.T) {
|
||||||
patchGood1 := types.PatchStrategicMerge("patch1.yaml")
|
patchGood1 := types.PatchStrategicMerge("patch1.yaml")
|
||||||
patch1 := `
|
patch1 := `
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ require (
|
|||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/api v0.5.1 => ../api
|
||||||
|
|
||||||
exclude (
|
exclude (
|
||||||
github.com/russross/blackfriday v2.0.0+incompatible
|
github.com/russross/blackfriday v2.0.0+incompatible
|
||||||
sigs.k8s.io/kustomize/api v0.2.0
|
sigs.k8s.io/kustomize/api v0.2.0
|
||||||
|
|||||||
@@ -750,8 +750,6 @@ sigs.k8s.io/controller-runtime v0.4.0 h1:wATM6/m+3w8lj8FXNaO6Fs/rq/vqoOjO1Q116Z9
|
|||||||
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
|
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
|
||||||
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
|
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
|
||||||
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
|
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
|
||||||
sigs.k8s.io/kustomize/api v0.5.1 h1:iHGTs5LcnJGqHstUSxWD/kX6XZgmd82x79LLlZwDU0I=
|
|
||||||
sigs.k8s.io/kustomize/api v0.5.1/go.mod h1:LGqJ9ZWOnWDqlECqrFgNUyEqSJc6ooA9ZiWZ4KFZv+I=
|
|
||||||
sigs.k8s.io/kustomize/cmd/config v0.2.0 h1:VNAWKb1JLl7dFjMAD5MwdZpGjreN3qL63C8DKtsUYck=
|
sigs.k8s.io/kustomize/cmd/config v0.2.0 h1:VNAWKb1JLl7dFjMAD5MwdZpGjreN3qL63C8DKtsUYck=
|
||||||
sigs.k8s.io/kustomize/cmd/config v0.2.0/go.mod h1:oXzY7QJS6JlmWgusEjra2O3cW7GSIICXa59/3DvjBfE=
|
sigs.k8s.io/kustomize/cmd/config v0.2.0/go.mod h1:oXzY7QJS6JlmWgusEjra2O3cW7GSIICXa59/3DvjBfE=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.1.4/go.mod h1:461i94nj0h0ylJ6w83jLkR4SqqVhn1iY6fjD0JSTQeE=
|
sigs.k8s.io/kustomize/kyaml v0.1.4/go.mod h1:461i94nj0h0ylJ6w83jLkR4SqqVhn1iY6fjD0JSTQeE=
|
||||||
|
|||||||
Reference in New Issue
Block a user