Skip to content

Commit

Permalink
Merge pull request #1288 from vincepri/add-test-unstrucutred-list
Browse files Browse the repository at this point in the history
🌱 Add test that checks List works on UnstructuredList not in Scheme
  • Loading branch information
k8s-ci-robot committed Dec 3, 2020
2 parents 758d268 + 52ba546 commit 43331a6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,36 @@ var _ = Describe("Client", func() {
close(done)
}, serverSideTimeoutSeconds)

It("should fetch unstructured collection of objects, even if scheme is empty", func(done Done) {
By("create an initial object")
_, err := clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())

cl, err := client.New(cfg, client.Options{Scheme: runtime.NewScheme()})
Expect(err).NotTo(HaveOccurred())

By("listing all objects of that type in the cluster")
deps := &unstructured.UnstructuredList{}
deps.SetGroupVersionKind(schema.GroupVersionKind{
Group: "apps",
Kind: "DeploymentList",
Version: "v1",
})
err = cl.List(context.Background(), deps)
Expect(err).NotTo(HaveOccurred())

Expect(deps.Items).NotTo(BeEmpty())
hasDep := false
for _, item := range deps.Items {
if item.GetName() == dep.Name && item.GetNamespace() == dep.Namespace {
hasDep = true
break
}
}
Expect(hasDep).To(BeTrue())
close(done)
}, serverSideTimeoutSeconds)

It("should return an empty list if there are no matching objects", func(done Done) {
cl, err := client.New(cfg, client.Options{})
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 43331a6

Please sign in to comment.