add testcase that yield malformed yaml errors

This commit is contained in:
charles-chenzz
2023-12-26 19:52:39 +08:00
parent bfb00ecb27
commit 3f921e159b

View File

@@ -29,6 +29,20 @@ spec:
- port: 7002 - 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) { func TestTargetMustHaveKustomizationFile(t *testing.T) {
th := kusttest_test.MakeHarness(t) th := kusttest_test.MakeHarness(t)
th.WriteF("service.yaml", ` th.WriteF("service.yaml", `
@@ -283,6 +297,14 @@ resources:
// know resource is file. // know resource is file.
errDir: `new root '%s' cannot be absolute`, 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) { t.Run(test.name, func(t *testing.T) {
// Should use real file system to indicate that we are creating // 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 // TODO(annasong): add tests that check accumulateResources errors for
// - repos // - repos
// - local directories // - local directories
// - files that yield malformed yaml errors
} }