Skip to content

Commit 52ba546

Browse files
committed
Add test that checks List works on UnstructuredList not in Scheme
After adding the metadata only watch and client support, the List object was type checking on Unstructured instead of UnstructuredList. Now! "Why were the tests passing??" one might ask, it seems that even though our tests had some using UnstructuredLists and querying against List, the objects we were asking (appsv1/Deployments) are core objects that are usually included in the default client-go scheme.Scheme. For the above reason, the internal typedClient was able to make the request to the API server and convert the list of object back to UnstructuredList. Signed-off-by: Vince Prignano <[email protected]>
1 parent 758d268 commit 52ba546

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/client/client_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,36 @@ var _ = Describe("Client", func() {
16861686
close(done)
16871687
}, serverSideTimeoutSeconds)
16881688

1689+
It("should fetch unstructured collection of objects, even if scheme is empty", func(done Done) {
1690+
By("create an initial object")
1691+
_, err := clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
1692+
Expect(err).NotTo(HaveOccurred())
1693+
1694+
cl, err := client.New(cfg, client.Options{Scheme: runtime.NewScheme()})
1695+
Expect(err).NotTo(HaveOccurred())
1696+
1697+
By("listing all objects of that type in the cluster")
1698+
deps := &unstructured.UnstructuredList{}
1699+
deps.SetGroupVersionKind(schema.GroupVersionKind{
1700+
Group: "apps",
1701+
Kind: "DeploymentList",
1702+
Version: "v1",
1703+
})
1704+
err = cl.List(context.Background(), deps)
1705+
Expect(err).NotTo(HaveOccurred())
1706+
1707+
Expect(deps.Items).NotTo(BeEmpty())
1708+
hasDep := false
1709+
for _, item := range deps.Items {
1710+
if item.GetName() == dep.Name && item.GetNamespace() == dep.Namespace {
1711+
hasDep = true
1712+
break
1713+
}
1714+
}
1715+
Expect(hasDep).To(BeTrue())
1716+
close(done)
1717+
}, serverSideTimeoutSeconds)
1718+
16891719
It("should return an empty list if there are no matching objects", func(done Done) {
16901720
cl, err := client.New(cfg, client.Options{})
16911721
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)