mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 18:10:59 +00:00
Suggested changes
This commit is contained in:
@@ -33,7 +33,7 @@ items:
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
replicas: 1
|
||||
- kind: Service
|
||||
@@ -42,7 +42,7 @@ items:
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -77,13 +77,28 @@ items:
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
actual, err := ioutil.ReadFile(filepath.Join(d, "f1.json"))
|
||||
actual, err := ioutil.ReadFile(filepath.Join(d, "f1.yaml"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
expected := `'{"kind":"Deployment","metadata":{"annotations":{"app":"nginx2"},"labels":{"app":"nginx2"},"name":"foo"},"spec":{"replicas":1}}'
|
||||
expected := `kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
'{"kind":"Service","metadata":{"annotations":{"app":"nginx"},"name":"foo"},"spec":{"selector":{"app":"nginx"}}}'
|
||||
kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
`
|
||||
if !assert.Equal(t, expected, string(actual)) {
|
||||
t.FailNow()
|
||||
@@ -121,6 +136,60 @@ spec:
|
||||
}
|
||||
}
|
||||
|
||||
func TestSinkCommandJSON(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
r := commands.GetSinkRunner("")
|
||||
r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
config.kubernetes.io/format: 'json'
|
||||
spec:
|
||||
replicas: 1
|
||||
`))
|
||||
r.Command.SetArgs([]string{d})
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
actual, err := ioutil.ReadFile(filepath.Join(d, "f1.json"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
expected := `{
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"labels": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1
|
||||
}
|
||||
}
|
||||
`
|
||||
if !assert.Equal(t, expected, string(actual)) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSinkCommand_Stdout(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
@@ -234,3 +303,57 @@ spec:
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSinkCommandJSON_Stdout(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
// fmt the files
|
||||
out := &bytes.Buffer{}
|
||||
r := commands.GetSinkRunner("")
|
||||
r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/format: 'json'
|
||||
spec:
|
||||
replicas: 1
|
||||
`))
|
||||
|
||||
r.Command.SetOut(out)
|
||||
r.Command.SetArgs([]string{})
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
expected := `{
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"labels": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1
|
||||
}
|
||||
}
|
||||
`
|
||||
if !assert.Equal(t, expected, out.String()) {
|
||||
println(out.String())
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (r *SourceRunner) runE(c *cobra.Command, args []string) error {
|
||||
inputs = append(inputs, kio.LocalPackageReader{PackagePath: a, MatchFilesGlob: kio.MatchAll})
|
||||
}
|
||||
if len(inputs) == 0 {
|
||||
inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}}
|
||||
inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin(), AcceptJSON: true}}
|
||||
}
|
||||
|
||||
err := kio.Pipeline{Inputs: inputs, Outputs: outputs}.Execute()
|
||||
|
||||
@@ -21,37 +21,25 @@ func TestSourceCommand(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f1.json"), []byte(`
|
||||
{
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"name": "foo",
|
||||
"annotations": {
|
||||
"app": "nginx2"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
@@ -98,22 +86,22 @@ kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
replicas: 1
|
||||
- kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
name: foo
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -147,6 +135,96 @@ items:
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceCommandJSON(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f1.json"), []byte(`
|
||||
{
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"name": "foo",
|
||||
"annotations": {
|
||||
"app": "nginx2"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1
|
||||
}
|
||||
}
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f2.json"), []byte(`
|
||||
{
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 3
|
||||
}
|
||||
}
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// fmt the files
|
||||
b := &bytes.Buffer{}
|
||||
r := commands.GetSourceRunner("")
|
||||
r.Command.SetArgs([]string{d})
|
||||
r.Command.SetOut(b)
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/format: 'json'
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.json'
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
spec:
|
||||
replicas: 1
|
||||
- apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.kubernetes.io/format: 'json'
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f2.json'
|
||||
name: foo
|
||||
spec:
|
||||
replicas: 3
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceCommand_Stdin(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
@@ -210,3 +288,56 @@ items:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceCommandJSON_Stdin(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
in := bytes.NewBufferString(`
|
||||
{
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx2"
|
||||
},
|
||||
"name": "foo",
|
||||
"annotations": {
|
||||
"app": "nginx2"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
r := commands.GetSourceRunner("")
|
||||
r.Command.SetArgs([]string{})
|
||||
r.Command.SetIn(in)
|
||||
r.Command.SetOut(out)
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/format: 'json'
|
||||
config.kubernetes.io/index: '0'
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
spec:
|
||||
replicas: 1
|
||||
`, out.String()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user