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

Function TestList

deprecated-dynamic/client_test.go:74–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

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
ResourceMethod · 0.65

Tested by

no test coverage detected