From 3f921e159bfddac3ff71ac57ff6c0db59a0c3f8f Mon Sep 17 00:00:00 2001 From: charles-chenzz Date: Tue, 26 Dec 2023 19:52:39 +0800 Subject: [PATCH] add testcase that yield malformed yaml errors --- api/krusty/accumulation_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/api/krusty/accumulation_test.go b/api/krusty/accumulation_test.go index 00bb7aa3a9..b5aee1ca1a 100644 --- a/api/krusty/accumulation_test.go +++ b/api/krusty/accumulation_test.go @@ -29,6 +29,20 @@ spec: - port: 7002 ` +const invalidResource = `apiVersion: v1 +kind: Service +metadata: + name: kapacitor + labels: + app.kubernetes.io/name: tick-kapacitor +spec: + selector: + app.kubernetes.io/name: tick-kapacitor + - name: http + port: 9092 + protocol: TCP + type: ClusterIP` + func TestTargetMustHaveKustomizationFile(t *testing.T) { th := kusttest_test.MakeHarness(t) th.WriteF("service.yaml", ` @@ -283,6 +297,14 @@ resources: // know resource is file. errDir: `new root '%s' cannot be absolute`, }, + { + name: "malformed yaml yields an error", + resource: "service.yaml", + files: map[string]string{ + "service.yaml": invalidResource, + }, + errFile: "MalformedYAMLError", + }, } { t.Run(test.name, func(t *testing.T) { // Should use real file system to indicate that we are creating @@ -306,5 +328,4 @@ resources: // TODO(annasong): add tests that check accumulateResources errors for // - repos // - local directories - // - files that yield malformed yaml errors }