mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-26 07:02:01 +00:00
fake dynamic client: support *List kinds
Today the dynamic fake client is not aware of *List kinds, so List calls return UnstructuredList objects without TypeMeta. This patch updates client-go's fake object tracker to store a map of GVR to list GVKs. In this way, the list GVK can be set for UnstructuredList objects. Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com> Kubernetes-commit: 0845b863e89912e0d6c4380f8bc362646326386a
This commit is contained in:
parent
bcecfeab18
commit
1db2969ba9
@ -84,6 +84,46 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ListKind(t *testing.T) {
|
||||
scheme := runtime.NewScheme()
|
||||
|
||||
client := NewSimpleDynamicClient(scheme,
|
||||
&unstructured.UnstructuredList{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "group/version",
|
||||
"kind": "TheKindList",
|
||||
},
|
||||
Items: []unstructured.Unstructured{
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-bar"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-baz"),
|
||||
},
|
||||
},
|
||||
)
|
||||
listFirst, err := client.Resource(schema.GroupVersionResource{Group: "group", Version: "version", Resource: "thekinds"}).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedList := &unstructured.UnstructuredList{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "group/version",
|
||||
"kind": "TheKindList",
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": "",
|
||||
},
|
||||
},
|
||||
Items: []unstructured.Unstructured{
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-bar"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-baz"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"),
|
||||
},
|
||||
}
|
||||
if !equality.Semantic.DeepEqual(listFirst, expectedList) {
|
||||
t.Fatal(diff.ObjectGoPrintDiff(expectedList, listFirst))
|
||||
}
|
||||
}
|
||||
|
||||
type patchTestCase struct {
|
||||
name string
|
||||
object runtime.Object
|
||||
|
Loading…
Reference in New Issue
Block a user