From 503a0905c06f816e1ffb5cadbd78d1c0041caaf0 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Fri, 7 Jun 2024 10:55:01 +0200 Subject: [PATCH] client-go/util/consistencydetector: extend TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath to work with unstructured list Kubernetes-commit: a2a48a475b4c98daeea3f83b8a89aa070ea4082b --- .../list_data_consistency_detector_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/util/consistencydetector/list_data_consistency_detector_test.go b/util/consistencydetector/list_data_consistency_detector_test.go index 0a0debd7..945e0731 100644 --- a/util/consistencydetector/list_data_consistency_detector_test.go +++ b/util/consistencydetector/list_data_consistency_detector_test.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/utils/ptr" ) @@ -78,6 +79,43 @@ func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath(t *testin TimeoutSeconds: ptr.To(int64(39)), }, }, + { + name: "list detector works with a unstructured list", + listResponse: &unstructured.UnstructuredList{ + Object: map[string]interface{}{ + "apiVersion": "vTest", + "kind": "rTestList", + "metadata": map[string]interface{}{ + "resourceVersion": "3", + }, + }, + Items: []unstructured.Unstructured{ + *makeUnstructuredObject("vTest", "rTest", "item1"), + *makeUnstructuredObject("vTest", "rTest", "item2"), + *makeUnstructuredObject("vTest", "rTest", "item3"), + }, + }, + retrievedListOptions: metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))}, + retrievedList: &unstructured.UnstructuredList{ + Object: map[string]interface{}{ + "apiVersion": "vTest", + "kind": "rTestList", + "metadata": map[string]interface{}{ + "resourceVersion": "3", + }, + }, + Items: []unstructured.Unstructured{ + *makeUnstructuredObject("vTest", "rTest", "item1"), + *makeUnstructuredObject("vTest", "rTest", "item2"), + *makeUnstructuredObject("vTest", "rTest", "item3"), + }, + }, + expectedRequestOptions: metav1.ListOptions{ + ResourceVersion: "3", + ResourceVersionMatch: metav1.ResourceVersionMatchExact, + TimeoutSeconds: ptr.To(int64(39)), + }, + }, } for _, scenario := range scenarios { t.Run(scenario.name, func(t *testing.T) {