Add integration test for glob support

This commit is contained in:
Jingfang Liu
2018-06-27 11:01:49 -07:00
parent 6392e6629f
commit 2a3f09a2f0
8 changed files with 40 additions and 26 deletions

View File

@@ -6,5 +6,4 @@ commonLabels:
commonAnnotations:
note: This is a test annotation
resources:
- deployment.yaml
- service.yaml
- resources/*.yaml

View File

@@ -2,8 +2,7 @@ namePrefix: staging-
commonLabels:
env: staging
patches:
- deployment-patch1.yaml
- deployment-patch2.yaml
- patches/deployment-patch*.yaml
bases:
- ../package/
configMapGenerator:

View File

@@ -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)
}

View File

@@ -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()
}