diff --git a/pkg/gather/clusterconfig/clusterconfig_test.go b/pkg/gather/clusterconfig/clusterconfig_test.go index 1e39fe4ff..d06171ca8 100644 --- a/pkg/gather/clusterconfig/clusterconfig_test.go +++ b/pkg/gather/clusterconfig/clusterconfig_test.go @@ -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" @@ -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 {