mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-17 14:56:31 +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"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/utils/ptr"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,26 +53,43 @@ func TestCheckListFromCacheDataConsistencyIfRequestedInternalPanics(t *testing.T
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath(t *testing.T) {
|
func TestCheckListFromCacheDataConsistencyIfRequestedInternalHappyPath(t *testing.T) {
|
||||||
ctx := context.TODO()
|
scenarios := []struct {
|
||||||
listOptions := metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))}
|
name string
|
||||||
expectedRequestOptions := metav1.ListOptions{
|
listResponse runtime.Object
|
||||||
|
retrievedList runtime.Object
|
||||||
|
retrievedListOptions metav1.ListOptions
|
||||||
|
|
||||||
|
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",
|
ResourceVersion: "2",
|
||||||
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
||||||
TimeoutSeconds: ptr.To(int64(39)),
|
TimeoutSeconds: ptr.To(int64(39)),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
listResponse := &v1.PodList{
|
for _, scenario := range scenarios {
|
||||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
t.Run(scenario.name, func(t *testing.T) {
|
||||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
ctx := context.TODO()
|
||||||
}
|
listOptions := metav1.ListOptions{TimeoutSeconds: ptr.To(int64(39))}
|
||||||
retrievedList := &v1.PodList{
|
fakeLister := &listWrapper{response: scenario.listResponse}
|
||||||
ListMeta: metav1.ListMeta{ResourceVersion: "2"},
|
|
||||||
Items: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
|
|
||||||
}
|
|
||||||
fakeLister := &listWrapper{response: listResponse}
|
|
||||||
|
|
||||||
checkListFromCacheDataConsistencyIfRequestedInternal(ctx, "", fakeLister.List, listOptions, retrievedList)
|
checkListFromCacheDataConsistencyIfRequestedInternal(ctx, "", fakeLister.List, listOptions, scenario.retrievedList)
|
||||||
|
|
||||||
require.Equal(t, 1, fakeLister.counter)
|
require.Equal(t, 1, fakeLister.counter)
|
||||||
require.Equal(t, 1, len(fakeLister.requestOptions))
|
require.Equal(t, 1, len(fakeLister.requestOptions))
|
||||||
require.Equal(t, fakeLister.requestOptions[0], expectedRequestOptions)
|
require.Equal(t, fakeLister.requestOptions[0], scenario.expectedRequestOptions)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user