@@ -24,6 +24,7 @@ import (
24
24
25
25
v1 "k8s.io/api/core/v1"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ "k8s.io/apimachinery/pkg/runtime"
27
28
"k8s.io/utils/ptr"
28
29
)
29
30
@@ -52,26 +53,43 @@ func TestCheckListFromCacheDataConsistencyIfRequestedInternalPanics(t *testing.T
52
53
}
53
54
54
55
func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath (t * testing.T ) {
55
- ctx := context .TODO ()
56
- listOptions := metav1.ListOptions {TimeoutSeconds : ptr .To (int64 (39 ))}
57
- expectedRequestOptions := metav1.ListOptions {
58
- ResourceVersion : "2" ,
59
- ResourceVersionMatch : metav1 .ResourceVersionMatchExact ,
60
- TimeoutSeconds : ptr .To (int64 (39 )),
61
- }
62
- listResponse := & v1.PodList {
63
- ListMeta : metav1.ListMeta {ResourceVersion : "2" },
64
- Items : []v1.Pod {* makePod ("p1" , "1" ), * makePod ("p2" , "2" )},
56
+ scenarios := []struct {
57
+ name string
58
+ listResponse runtime.Object
59
+ retrievedList runtime.Object
60
+ retrievedListOptions metav1.ListOptions
61
+
62
+ expectedRequestOptions metav1.ListOptions
63
+ }{
64
+ {
65
+ name : "list detector works with a typed list" ,
66
+ listResponse : & v1.PodList {
67
+ ListMeta : metav1.ListMeta {ResourceVersion : "2" },
68
+ Items : []v1.Pod {* makePod ("p1" , "1" ), * makePod ("p2" , "2" )},
69
+ },
70
+ retrievedListOptions : metav1.ListOptions {TimeoutSeconds : ptr .To (int64 (39 ))},
71
+ retrievedList : & v1.PodList {
72
+ ListMeta : metav1.ListMeta {ResourceVersion : "2" },
73
+ Items : []v1.Pod {* makePod ("p1" , "1" ), * makePod ("p2" , "2" )},
74
+ },
75
+ expectedRequestOptions : metav1.ListOptions {
76
+ ResourceVersion : "2" ,
77
+ ResourceVersionMatch : metav1 .ResourceVersionMatchExact ,
78
+ TimeoutSeconds : ptr .To (int64 (39 )),
79
+ },
80
+ },
65
81
}
66
- retrievedList := & v1.PodList {
67
- ListMeta : metav1.ListMeta {ResourceVersion : "2" },
68
- Items : []v1.Pod {* makePod ("p1" , "1" ), * makePod ("p2" , "2" )},
82
+ for _ , scenario := range scenarios {
83
+ t .Run (scenario .name , func (t * testing.T ) {
84
+ ctx := context .TODO ()
85
+ listOptions := metav1.ListOptions {TimeoutSeconds : ptr .To (int64 (39 ))}
86
+ fakeLister := & listWrapper {response : scenario .listResponse }
87
+
88
+ checkListFromCacheDataConsistencyIfRequestedInternal (ctx , "" , fakeLister .List , listOptions , scenario .retrievedList )
89
+
90
+ require .Equal (t , 1 , fakeLister .counter )
91
+ require .Equal (t , 1 , len (fakeLister .requestOptions ))
92
+ require .Equal (t , fakeLister .requestOptions [0 ], scenario .expectedRequestOptions )
93
+ })
69
94
}
70
- fakeLister := & listWrapper {response : listResponse }
71
-
72
- checkListFromCacheDataConsistencyIfRequestedInternal (ctx , "" , fakeLister .List , listOptions , retrievedList )
73
-
74
- require .Equal (t , 1 , fakeLister .counter )
75
- require .Equal (t , 1 , len (fakeLister .requestOptions ))
76
- require .Equal (t , fakeLister .requestOptions [0 ], expectedRequestOptions )
77
95
}
0 commit comments