MCPcopy
hub / github.com/kubernetes/client-go / TestList

Function TestList

dynamic/client_test.go:73–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestList(t *testing.T) {
74 tcs := []struct {
75 name string
76 namespace string
77 path string
78 resp []byte
79 want *unstructured.UnstructuredList
80 }{
81 {
82 name: "normal_list",
83 path: "/apis/gtest/vtest/rtest",
84 resp: getListJSON("vTest", "rTestList",
85 getJSON("vTest", "rTest", "item1"),
86 getJSON("vTest", "rTest", "item2")),
87 want: &unstructured.UnstructuredList{
88 Object: map[string]interface{}{
89 "apiVersion": "vTest",
90 "kind": "rTestList",
91 },
92 Items: []unstructured.Unstructured{
93 *getObject("vTest", "rTest", "item1"),
94 *getObject("vTest", "rTest", "item2"),
95 },
96 },
97 },
98 {
99 name: "namespaced_list",
100 namespace: "nstest",
101 path: "/apis/gtest/vtest/namespaces/nstest/rtest",
102 resp: getListJSON("vTest", "rTestList",
103 getJSON("vTest", "rTest", "item1"),
104 getJSON("vTest", "rTest", "item2")),
105 want: &unstructured.UnstructuredList{
106 Object: map[string]interface{}{
107 "apiVersion": "vTest",
108 "kind": "rTestList",
109 },
110 Items: []unstructured.Unstructured{
111 *getObject("vTest", "rTest", "item1"),
112 *getObject("vTest", "rTest", "item2"),
113 },
114 },
115 },
116 }
117 for _, tc := range tcs {
118 resource := schema.GroupVersionResource{Group: "gtest", Version: "vtest", Resource: "rtest"}
119 cl, srv, err := getClientServer(func(w http.ResponseWriter, r *http.Request) {
120 if r.Method != "GET" {
121 t.Errorf("List(%q) got HTTP method %s. wanted GET", tc.name, r.Method)
122 }
123
124 if r.URL.Path != tc.path {
125 t.Errorf("List(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path)
126 }
127
128 w.Header().Set("Content-Type", runtime.ContentTypeJSON)
129 w.Write(tc.resp)
130 })

Callers

nothing calls this directly

Calls 11

WriteMethod · 0.80
getListJSONFunction · 0.70
getJSONFunction · 0.70
getObjectFunction · 0.70
getClientServerFunction · 0.70
ErrorfMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
ListMethod · 0.65
NamespaceMethod · 0.65
ResourceMethod · 0.65

Tested by

no test coverage detected