Skip to content

Commit

Permalink
Add test for VolumeSnapshot CRD collection
Browse files Browse the repository at this point in the history
  • Loading branch information
natiiix committed Aug 21, 2020
1 parent cc5e1cd commit 2136bc8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/gather/clusterconfig/clusterconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

imageregistryv1 "github.com/openshift/api/imageregistry/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apixv1beta1clientfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kubefake "k8s.io/client-go/kubernetes/fake"
Expand Down Expand Up @@ -435,6 +437,36 @@ func TestGatherContainerImages(t *testing.T) {
}
}

func TestCollectVolumeSnapshotCRD(t *testing.T) {
crdNames := []string{
"unrelated.custom.resource.definition.k8s.io",
"volumesnapshots.snapshot.storage.k8s.io",
"volumesnapshotcontents.snapshot.storage.k8s.io",
"another.irrelevant.custom.resource.definition.k8s.io",
"this.should.not.be.gathered.k8s.io",
}

crdClientset := apixv1beta1clientfake.NewSimpleClientset()

for _, name := range crdNames {
crdClientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(&v1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: name},
})
}

gatherer := &Gatherer{crdClient: crdClientset.ApiextensionsV1beta1()}
records, errs := GatherCRD(gatherer)()
if len(errs) != 0 {
t.Fatalf("gather CRDs resulted in error: %#v", errs)
}

if len(records) != 2 {
t.Fatalf("unexpected CRDs gathered: %#v", records)
}

// TODO: More in-depth test.
}

func ExampleGatherMostRecentMetrics_Test() {
b, err := ExampleMostRecentMetrics()
if err != nil {
Expand Down

0 comments on commit 2136bc8

Please sign in to comment.