Skip to content

Commit c8971c4

Browse files
committed
client-go/consistencydetector: extend TestDataConsistencyChecker to test unstructured data
1 parent d535f55 commit c8971c4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

staging/src/k8s.io/client-go/util/consistencydetector/data_consistency_detector_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
v1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/apimachinery/pkg/types"
3031
"k8s.io/utils/ptr"
@@ -62,6 +63,34 @@ func TestDataConsistencyChecker(t *testing.T) {
6263
},
6364
},
6465

66+
{
67+
name: "data consistency check works with unstructured data (dynamic client)",
68+
lastSyncedResourceVersion: "2",
69+
listResponse: &unstructured.UnstructuredList{
70+
Object: map[string]interface{}{
71+
"apiVersion": "vTest",
72+
"kind": "rTestList",
73+
},
74+
Items: []unstructured.Unstructured{
75+
*makeUnstructuredObject("vTest", "rTest", "item1"),
76+
*makeUnstructuredObject("vTest", "rTest", "item2"),
77+
},
78+
},
79+
requestOptions: metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))},
80+
retrievedItems: []runtime.Object{
81+
makeUnstructuredObject("vTest", "rTest", "item1"),
82+
makeUnstructuredObject("vTest", "rTest", "item2"),
83+
},
84+
expectedListRequests: 1,
85+
expectedRequestOptions: []metav1.ListOptions{
86+
{
87+
ResourceVersion: "2",
88+
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
89+
TimeoutSeconds: ptr.To(int64(39)),
90+
},
91+
},
92+
},
93+
6594
{
6695
name: "legacy, the limit is removed from the list options when it wasn't honored by the watch cache",
6796
lastSyncedResourceVersion: "2",
@@ -238,3 +267,15 @@ func (lw *listWrapper) List(_ context.Context, opts metav1.ListOptions) (runtime
238267
func makePod(name, rv string) *v1.Pod {
239268
return &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: name, ResourceVersion: rv, UID: types.UID(name)}}
240269
}
270+
271+
func makeUnstructuredObject(version, kind, name string) *unstructured.Unstructured {
272+
return &unstructured.Unstructured{
273+
Object: map[string]interface{}{
274+
"apiVersion": version,
275+
"kind": kind,
276+
"metadata": map[string]interface{}{
277+
"name": name,
278+
},
279+
},
280+
}
281+
}

0 commit comments

Comments
 (0)