mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Print Krmfile data for cfg tree
This commit is contained in:
@@ -90,6 +90,109 @@ spec:
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeCommand_subpkgs(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-tree-test")
|
||||
defer os.RemoveAll(d)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Join(d, "subpkg"), 0700)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
|
||||
apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
name: foo
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(d, "subpkg", "f2.yaml"), []byte(`kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "Krmfile"), []byte(`apiVersion: kpt.dev/v1alpha1
|
||||
kind: Krmfile
|
||||
metadata:
|
||||
name: mainpkg
|
||||
openAPI:
|
||||
definitions:
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(d, "subpkg", "Krmfile"), []byte(`apiVersion: kpt.dev/v1alpha1
|
||||
kind: Krmfile
|
||||
metadata:
|
||||
name: subpkg
|
||||
openAPI:
|
||||
definitions:
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// fmt the files
|
||||
b := &bytes.Buffer{}
|
||||
r := commands.GetTreeRunner("")
|
||||
r.Command.SetArgs([]string{d})
|
||||
r.Command.SetOut(b)
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
if !assert.Equal(t, fmt.Sprintf(`%s
|
||||
├── [Krmfile] Krmfile mainpkg
|
||||
├── [f1.yaml] Deployment foo
|
||||
├── [f1.yaml] Service foo
|
||||
└── Pkg: subpkg
|
||||
├── [Krmfile] Krmfile subpkg
|
||||
└── [f2.yaml] Deployment bar
|
||||
`, d), b.String()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeCommand_stdin(t *testing.T) {
|
||||
// fmt the files
|
||||
b := &bytes.Buffer{}
|
||||
|
||||
Reference in New Issue
Block a user