mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-16 22:36:48 +00:00
client-go/util/consistencydetector: refactor TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath to work with unstructured data
Kubernetes-commit: c5904424b2b03cec1befaf16c55bb97df57669bc
This commit is contained in:
parent
e8224736d3
commit
2d885a2ed5
@ -24,6 +24,7 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/utils/ptr"
|
||||
)
|
||||
|
||||
@ -52,26 +53,43 @@ func TestCheckListFromCacheDataConsistencyIfRequestedInternalPanics(t *testing.T
|
||||
}
|
||||
|
||||
func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
listOptions := metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))}
|
||||
expectedRequestOptions := metav1.ListOptions{
|
||||
ResourceVersion: "2",
|
||||
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
||||
TimeoutSeconds: ptr.To(int64(39)),
|
||||
}
|
||||
listResponse := &v1.PodList{
|
||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
||||
}
|
||||
retrievedList := &v1.PodList{
|
||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
||||
}
|
||||
fakeLister := &listWrapper{response: listResponse}
|
||||
scenarios := []struct {
|
||||
name string
|
||||
listResponse runtime.Object
|
||||
retrievedList runtime.Object
|
||||
retrievedListOptions metav1.ListOptions
|
||||
|
||||
checkListFromCacheDataConsistencyIfRequestedInternal(ctx, "", fakeLister.List, listOptions, retrievedList)
|
||||
expectedRequestOptions metav1.ListOptions
|
||||
}{
|
||||
{
|
||||
name: "list detector works with a typed list",
|
||||
listResponse: &v1.PodList{
|
||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
||||
},
|
||||
retrievedListOptions: metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))},
|
||||
retrievedList: &v1.PodList{
|
||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
||||
},
|
||||
expectedRequestOptions: metav1.ListOptions{
|
||||
ResourceVersion: "2",
|
||||
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
||||
TimeoutSeconds: ptr.To(int64(39)),
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, scenario := range scenarios {
|
||||
t.Run(scenario.name, func(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
listOptions := metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))}
|
||||
fakeLister := &listWrapper{response: scenario.listResponse}
|
||||
|
||||
require.Equal(t, 1, fakeLister.counter)
|
||||
require.Equal(t, 1, len(fakeLister.requestOptions))
|
||||
require.Equal(t, fakeLister.requestOptions[0], expectedRequestOptions)
|
||||
checkListFromCacheDataConsistencyIfRequestedInternal(ctx, "", fakeLister.List, listOptions, scenario.retrievedList)
|
||||
|
||||
require.Equal(t, 1, fakeLister.counter)
|
||||
require.Equal(t, 1, len(fakeLister.requestOptions))
|
||||
require.Equal(t, fakeLister.requestOptions[0], scenario.expectedRequestOptions)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user