mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Cat with subpackages
This commit is contained in:
@@ -8,10 +8,13 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||
"sigs.k8s.io/kustomize/kyaml/openapi"
|
||||
)
|
||||
|
||||
// TODO(pwittrock): write tests for reading / writing ResourceLists
|
||||
@@ -112,6 +115,7 @@ metadata:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
@@ -223,6 +227,7 @@ metadata:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
@@ -305,6 +310,7 @@ metadata:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
@@ -420,6 +426,7 @@ metadata:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
`, string(actual)) {
|
||||
return
|
||||
}
|
||||
@@ -536,7 +543,138 @@ metadata:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
`, string(actual)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatSubPackages(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
dataset string
|
||||
packagePath string
|
||||
args []string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "cat-recurse-subpackages",
|
||||
dataset: "dataset-without-setters",
|
||||
expected: `
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mysql-deployment
|
||||
namespace: myspace
|
||||
spec:
|
||||
replicas: 3
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: mysql
|
||||
image: mysql:1.7.9
|
||||
---
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: storage-deployment
|
||||
namespace: myspace
|
||||
spec:
|
||||
replicas: 4
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: storage
|
||||
image: storage:1.7.7
|
||||
---
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "cat-top-level-pkg-no-recurse-subpackages",
|
||||
dataset: "dataset-without-setters",
|
||||
args: []string{"-R=false"},
|
||||
packagePath: "mysql",
|
||||
expected: `
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mysql-deployment
|
||||
namespace: myspace
|
||||
spec:
|
||||
replicas: 3
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: mysql
|
||||
image: mysql:1.7.9
|
||||
---
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "cat-nested-pkg-no-recurse-subpackages",
|
||||
dataset: "dataset-without-setters",
|
||||
packagePath: "mysql/storage",
|
||||
args: []string{"-R=false"},
|
||||
expected: `
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: storage-deployment
|
||||
namespace: myspace
|
||||
spec:
|
||||
replicas: 4
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: storage
|
||||
image: storage:1.7.7
|
||||
---`,
|
||||
},
|
||||
}
|
||||
for i := range tests {
|
||||
test := tests[i]
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// reset the openAPI afterward
|
||||
openapi.ResetOpenAPI()
|
||||
defer openapi.ResetOpenAPI()
|
||||
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
||||
baseDir, err := ioutil.TempDir("", "")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
copyutil.CopyDir(sourceDir, baseDir)
|
||||
defer os.RemoveAll(baseDir)
|
||||
runner := commands.GetCatRunner("")
|
||||
actual := &bytes.Buffer{}
|
||||
runner.Command.SetOut(actual)
|
||||
runner.Command.SetArgs(append([]string{filepath.Join(baseDir, test.packagePath)}, test.args...))
|
||||
err = runner.Command.Execute()
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
if !assert.Equal(t, strings.TrimSpace(expectedNormalized), strings.TrimSpace(actualNormalized)) {
|
||||
t.FailNow()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user