From 2a3f09a2f008593933fc32a9e68b22745f937fd8 Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Wed, 27 Jun 2018 11:01:49 -0700 Subject: [PATCH] Add integration test for glob support --- .../testcase-base-only/in/kustomization.yaml | 3 +- .../in/{ => resources}/deployment.yaml | 0 .../in/{ => resources}/service.yaml | 0 .../in/overlay/kustomization.yaml | 3 +- .../{ => patches}/deployment-patch1.yaml | 0 .../{ => patches}/deployment-patch2.yaml | 0 pkg/crds/crds_test.go | 55 +++++++++++-------- pkg/transformers/pathconfig.go | 5 ++ 8 files changed, 40 insertions(+), 26 deletions(-) rename pkg/commands/testdata/testcase-base-only/in/{ => resources}/deployment.yaml (100%) rename pkg/commands/testdata/testcase-base-only/in/{ => resources}/service.yaml (100%) rename pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/{ => patches}/deployment-patch1.yaml (100%) rename pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/{ => patches}/deployment-patch2.yaml (100%) diff --git a/pkg/commands/testdata/testcase-base-only/in/kustomization.yaml b/pkg/commands/testdata/testcase-base-only/in/kustomization.yaml index eb8201580..c611072e2 100644 --- a/pkg/commands/testdata/testcase-base-only/in/kustomization.yaml +++ b/pkg/commands/testdata/testcase-base-only/in/kustomization.yaml @@ -6,5 +6,4 @@ commonLabels: commonAnnotations: note: This is a test annotation resources: - - deployment.yaml - - service.yaml + - resources/*.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/deployment.yaml b/pkg/commands/testdata/testcase-base-only/in/resources/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/deployment.yaml rename to pkg/commands/testdata/testcase-base-only/in/resources/deployment.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/service.yaml b/pkg/commands/testdata/testcase-base-only/in/resources/service.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/service.yaml rename to pkg/commands/testdata/testcase-base-only/in/resources/service.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml index 2ffc41519..d05ba42ae 100644 --- a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml @@ -2,8 +2,7 @@ namePrefix: staging- commonLabels: env: staging patches: - - deployment-patch1.yaml - - deployment-patch2.yaml + - patches/deployment-patch*.yaml bases: - ../package/ configMapGenerator: diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/deployment-patch1.yaml b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/deployment-patch1.yaml rename to pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/deployment-patch2.yaml b/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/deployment-patch2.yaml rename to pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml diff --git a/pkg/crds/crds_test.go b/pkg/crds/crds_test.go index a3696ef1a..637a6b7fb 100644 --- a/pkg/crds/crds_test.go +++ b/pkg/crds/crds_test.go @@ -18,6 +18,7 @@ package crds import ( "reflect" + "sort" "testing" "github.com/kubernetes-sigs/kustomize/pkg/internal/loadertest" @@ -150,30 +151,36 @@ func makeLoader(t *testing.T) loader.Loader { } func TestRegisterCRD(t *testing.T) { + refpathconfigs := []transformers.ReferencePathConfig{ + transformers.NewReferencePathConfig( + schema.GroupVersionKind{Kind: "Bee", Version: "v1beta1"}, + []transformers.PathConfig{ + { + CreateIfNotPresent: false, + GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, + Path: []string{"spec", "beeRef", "name"}, + }, + }, + ), + transformers.NewReferencePathConfig( + schema.GroupVersionKind{Kind: "Secret", Version: "v1"}, + []transformers.PathConfig{ + { + CreateIfNotPresent: false, + GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, + Path: []string{"spec", "secretRef", "name"}, + }, + }, + ), + } + + sort.Slice(refpathconfigs, func(i, j int) bool { + return refpathconfigs[i].GVK() < refpathconfigs[j].GVK() + }) + expected := []pathConfigs{ { - namereferencePathConfigs: []transformers.ReferencePathConfig{ - transformers.NewReferencePathConfig( - schema.GroupVersionKind{Kind: "Bee", Version: "v1beta1"}, - []transformers.PathConfig{ - { - CreateIfNotPresent: false, - GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, - Path: []string{"spec", "beeRef", "name"}, - }, - }, - ), - transformers.NewReferencePathConfig( - schema.GroupVersionKind{Kind: "Secret", Version: "v1"}, - []transformers.PathConfig{ - { - CreateIfNotPresent: false, - GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, - Path: []string{"spec", "secretRef", "name"}, - }, - }, - ), - }, + namereferencePathConfigs: refpathconfigs, }, } @@ -181,6 +188,10 @@ func TestRegisterCRD(t *testing.T) { pathconfig, _ := registerCRD(loader, "/testpath/crd.json") + sort.Slice(pathconfig[0].namereferencePathConfigs, func(i, j int) bool { + return pathconfig[0].namereferencePathConfigs[i].GVK() < pathconfig[0].namereferencePathConfigs[j].GVK() + }) + if !reflect.DeepEqual(pathconfig, expected) { t.Fatalf("expected\n %v\n but got\n %v\n", expected, pathconfig) } diff --git a/pkg/transformers/pathconfig.go b/pkg/transformers/pathconfig.go index 0c8fbf80a..b9e40fc9d 100644 --- a/pkg/transformers/pathconfig.go +++ b/pkg/transformers/pathconfig.go @@ -61,3 +61,8 @@ func NewReferencePathConfig(gvk schema.GroupVersionKind, pathconfigs []PathConfi pathConfigs: pathconfigs, } } + +// GVK returns the Group version kind of a Reference PathConfig +func (r ReferencePathConfig) GVK() string { + return r.referencedGVK.String() +}