Skip to content

Commit 1d263d2

Browse files
committed
replaceVars returns nil on nil input, not error
includes an integration test for 'null' args inputs
1 parent 0938014 commit 1d263d2

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

pkg/target/nullvalues_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package target
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func TestNullValues(t *testing.T) {
24+
th := NewKustTestHarness(t, "/app")
25+
th.writeF("/app/deployment.yaml", `
26+
apiVersion: apps/v1
27+
kind: Deployment
28+
metadata:
29+
labels:
30+
app: example
31+
name: example
32+
spec:
33+
selector:
34+
matchLabels:
35+
app: example
36+
template:
37+
metadata:
38+
labels:
39+
app: example
40+
spec:
41+
containers:
42+
- args: null
43+
image: image
44+
name: example
45+
`)
46+
th.writeF("/app/kustomization.yaml", `
47+
apiVersion: v1beta1
48+
kind: Kustomization
49+
resources:
50+
- deployment.yaml
51+
`)
52+
m, err := th.makeKustTarget().MakeCustomizedResMap()
53+
if err != nil {
54+
t.Fatalf("Err: %v", err)
55+
}
56+
57+
th.assertActualEqualsExpected(m, `
58+
apiVersion: apps/v1
59+
kind: Deployment
60+
metadata:
61+
labels:
62+
app: example
63+
name: example
64+
spec:
65+
selector:
66+
matchLabels:
67+
app: example
68+
template:
69+
metadata:
70+
labels:
71+
app: example
72+
spec:
73+
containers:
74+
- args: null
75+
image: image
76+
name: example
77+
`)
78+
}

pkg/transformers/refvars.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func (rv *refvarTransformer) replaceVars(in interface{}) (interface{}, error) {
4242
return nil, fmt.Errorf("%#v is expected to be %T", in, s)
4343
}
4444
return expansion.Expand(s, rv.mappingFunc), nil
45+
case nil:
46+
return nil, nil
4547
default:
4648
return "", fmt.Errorf("invalid type encountered %T", vt)
4749
}

0 commit comments

Comments
 (0)