Added test to ensure that individusal files cannot be added to the components list.

This commit is contained in:
Paul Martin
2020-05-19 19:26:18 +01:00
parent c5c53011da
commit ab9d4c7e7b

View File

@@ -359,18 +359,18 @@ resources:
}
}
func TestResourcesCannotBeAddedToComponents(t *testing.T) {
func TestKustomizationsCannotBeAddedToComponents(t *testing.T) {
th := kusttest_test.MakeHarness(t)
writeComponentBase(th)
writeComponentPatch(th)
th.WriteF("/app/resincust/kustomization.yaml", `
th.WriteF("/app/kustincomponents/kustomization.yaml", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
components:
- ../base
- ../patch
`)
err := th.RunWithErr("/app/resincust", th.MakeDefaultOptions())
err := th.RunWithErr("/app/kustincomponents", th.MakeDefaultOptions())
if !strings.Contains(
err.Error(),
"accumulating components: accumulateDirectory: \"expected kind 'Component' for path '/app/base' but got 'Kustomization'") {
@@ -378,6 +378,34 @@ components:
}
}
func TestFilesCannotBeAddedToComponentsList(t *testing.T) {
th := kusttest_test.MakeHarness(t)
writeComponentBase(th)
th.WriteF("/app/filesincomponents/stub.yaml", `
apiVersion: v1
kind: Deployment
metadata:
name: stub
spec:
replicas: 1
`)
th.WriteF("/app/filesincomponents/kustomization.yaml", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
components:
- stub.yaml
- ../patch
`)
err := th.RunWithErr("/app/filesincomponents", th.MakeDefaultOptions())
if !strings.Contains(
err.Error(),
"'/app/filesincomponents/stub.yaml' must be a directory to be a root") {
t.Fatalf("unexpected error: %s", err)
}
}
func TestMissingOptionalComponentApiVersion(t *testing.T) {
th := kusttest_test.MakeHarness(t)
writeComponentBase(th)