From 03bde77faeffbd54927b0f5c503cd9d405146be5 Mon Sep 17 00:00:00 2001 From: Gavin Bunney Date: Mon, 9 Dec 2024 13:00:42 -0800 Subject: [PATCH] Expand kustomize test coverage and update for later kustomize format --- ...source_kubectl_kustomize_documents_test.go | 70 ++++++++++++++++++- .../kustomize/helloWorld/kustomization.yaml | 9 ++- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/kubernetes/data_source_kubectl_kustomize_documents_test.go b/kubernetes/data_source_kubectl_kustomize_documents_test.go index 22625898..4c05dd58 100644 --- a/kubernetes/data_source_kubectl_kustomize_documents_test.go +++ b/kubernetes/data_source_kubectl_kustomize_documents_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -var kustTargetUrl = "https://github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6" +var kustTargetUrl = "https://github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v3.3.1" func TestAccKubectlDataSourceKustomizeDocuments_url(t *testing.T) { resource.Test(t, resource.TestCase{ @@ -28,7 +28,73 @@ func TestAccKubectlDataSourceKustomizeDocuments_localDir(t *testing.T) { Steps: []resource.TestStep{ { Config: kubectlKustomizeDocumentsConfig("../test/data/kustomize/helloWorld"), - Check: resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.#", "3"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.#", "3"), + resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.0", `apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: hello + name: the-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: hello + template: + metadata: + labels: + app: hello + deployment: hello + spec: + containers: + - command: + - /hello + - --port=8080 + - --enableRiskyFeature=$(ENABLE_RISKY) + env: + - name: ALT_GREETING + valueFrom: + configMapKeyRef: + key: altGreeting + name: the-map + - name: ENABLE_RISKY + valueFrom: + configMapKeyRef: + key: enableRisky + name: the-map + image: monopole/hello:1 + name: the-container + ports: + - containerPort: 8080 +`), + resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.1", `apiVersion: v1 +kind: Service +metadata: + labels: + app: hello + name: the-service +spec: + ports: + - port: 8666 + protocol: TCP + targetPort: 8080 + selector: + app: hello + deployment: hello + type: LoadBalancer +`), + resource.TestCheckResourceAttr("data.kubectl_kustomize_documents.test", "documents.2", `apiVersion: v1 +data: + altGreeting: Good Morning! + enableRisky: "false" +kind: ConfigMap +metadata: + labels: + app: hello + name: the-map +`), + ), }, }, }) diff --git a/test/data/kustomize/helloWorld/kustomization.yaml b/test/data/kustomize/helloWorld/kustomization.yaml index 41965951..990d758b 100644 --- a/test/data/kustomize/helloWorld/kustomization.yaml +++ b/test/data/kustomize/helloWorld/kustomization.yaml @@ -1,7 +1,12 @@ # Example configuration for the webserver # at https://github.com/monopole/hello -commonLabels: - app: hello + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +labels: + - includeSelectors: true + pairs: + app: hello resources: - deployment.yaml