Skip to content

Commit

Permalink
Add integration test for glob support
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Jun 27, 2018
1 parent 6392e66 commit 2a3f09a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
Expand Up @@ -6,5 +6,4 @@ commonLabels:
commonAnnotations:
note: This is a test annotation
resources:
- deployment.yaml
- service.yaml
- resources/*.yaml
Expand Up @@ -2,8 +2,7 @@ namePrefix: staging-
commonLabels:
env: staging
patches:
- deployment-patch1.yaml
- deployment-patch2.yaml
- patches/deployment-patch*.yaml
bases:
- ../package/
configMapGenerator:
Expand Down
55 changes: 33 additions & 22 deletions pkg/crds/crds_test.go
Expand Up @@ -18,6 +18,7 @@ package crds

import (
"reflect"
"sort"
"testing"

"github.com/kubernetes-sigs/kustomize/pkg/internal/loadertest"
Expand Down Expand Up @@ -150,37 +151,47 @@ 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,
},
}

loader := makeLoader(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)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/transformers/pathconfig.go
Expand Up @@ -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()
}

0 comments on commit 2a3f09a

Please sign in to comment.