Skip to content

Commit c9dc419

Browse files
authored
Expand kustomize test coverage and update for later kustomize format (#328)
1 parent c0eb6c2 commit c9dc419

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

kubernetes/data_source_kubectl_kustomize_documents_test.go

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
)
88

9-
var kustTargetUrl = "https://github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6"
9+
var kustTargetUrl = "https://github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v3.3.1"
1010

1111
func TestAccKubectlDataSourceKustomizeDocuments_url(t *testing.T) {
1212
resource.Test(t, resource.TestCase{
@@ -28,7 +28,73 @@ func TestAccKubectlDataSourceKustomizeDocuments_localDir(t *testing.T) {
2828
Steps: []resource.TestStep{
2929
{
3030
Config: kubectlKustomizeDocumentsConfig("../test/data/kustomize/helloWorld"),
31-
Check: resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.#", "3"),
31+
Check: resource.ComposeAggregateTestCheckFunc(
32+
resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.#", "3"),
33+
resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.0", `apiVersion: apps/v1
34+
kind: Deployment
35+
metadata:
36+
labels:
37+
app: hello
38+
name: the-deployment
39+
spec:
40+
replicas: 3
41+
selector:
42+
matchLabels:
43+
app: hello
44+
template:
45+
metadata:
46+
labels:
47+
app: hello
48+
deployment: hello
49+
spec:
50+
containers:
51+
- command:
52+
- /hello
53+
- --port=8080
54+
- --enableRiskyFeature=$(ENABLE_RISKY)
55+
env:
56+
- name: ALT_GREETING
57+
valueFrom:
58+
configMapKeyRef:
59+
key: altGreeting
60+
name: the-map
61+
- name: ENABLE_RISKY
62+
valueFrom:
63+
configMapKeyRef:
64+
key: enableRisky
65+
name: the-map
66+
image: monopole/hello:1
67+
name: the-container
68+
ports:
69+
- containerPort: 8080
70+
`),
71+
resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.1", `apiVersion: v1
72+
kind: Service
73+
metadata:
74+
labels:
75+
app: hello
76+
name: the-service
77+
spec:
78+
ports:
79+
- port: 8666
80+
protocol: TCP
81+
targetPort: 8080
82+
selector:
83+
app: hello
84+
deployment: hello
85+
type: LoadBalancer
86+
`),
87+
resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.2", `apiVersion: v1
88+
data:
89+
altGreeting: Good Morning!
90+
enableRisky: "false"
91+
kind: ConfigMap
92+
metadata:
93+
labels:
94+
app: hello
95+
name: the-map
96+
`),
97+
),
3298
},
3399
},
34100
})

test/data/kustomize/helloWorld/kustomization.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Example configuration for the webserver
22
# at https://github.com/monopole/hello
3-
commonLabels:
4-
app: hello
3+
4+
apiVersion: kustomize.config.k8s.io/v1beta1
5+
kind: Kustomization
6+
labels:
7+
- includeSelectors: true
8+
pairs:
9+
app: hello
510

611
resources:
712
- deployment.yaml

0 commit comments

Comments
 (0)