| 149 | } |
| 150 | |
| 151 | func TestGet(t *testing.T) { |
| 152 | tcs := []struct { |
| 153 | resource string |
| 154 | namespace string |
| 155 | name string |
| 156 | path string |
| 157 | resp []byte |
| 158 | want *unstructured.Unstructured |
| 159 | }{ |
| 160 | { |
| 161 | resource: "rtest", |
| 162 | name: "normal_get", |
| 163 | path: "/apis/gtest/vtest/rtest/normal_get", |
| 164 | resp: getJSON("vTest", "rTest", "normal_get"), |
| 165 | want: getObject("vTest", "rTest", "normal_get"), |
| 166 | }, |
| 167 | { |
| 168 | resource: "rtest", |
| 169 | namespace: "nstest", |
| 170 | name: "namespaced_get", |
| 171 | path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_get", |
| 172 | resp: getJSON("vTest", "rTest", "namespaced_get"), |
| 173 | want: getObject("vTest", "rTest", "namespaced_get"), |
| 174 | }, |
| 175 | { |
| 176 | resource: "rtest/srtest", |
| 177 | name: "normal_subresource_get", |
| 178 | path: "/apis/gtest/vtest/rtest/normal_subresource_get/srtest", |
| 179 | resp: getJSON("vTest", "srTest", "normal_subresource_get"), |
| 180 | want: getObject("vTest", "srTest", "normal_subresource_get"), |
| 181 | }, |
| 182 | { |
| 183 | resource: "rtest/srtest", |
| 184 | namespace: "nstest", |
| 185 | name: "namespaced_subresource_get", |
| 186 | path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_subresource_get/srtest", |
| 187 | resp: getJSON("vTest", "srTest", "namespaced_subresource_get"), |
| 188 | want: getObject("vTest", "srTest", "namespaced_subresource_get"), |
| 189 | }, |
| 190 | } |
| 191 | for _, tc := range tcs { |
| 192 | gv := &schema.GroupVersion{Group: "gtest", Version: "vtest"} |
| 193 | resource := &metav1.APIResource{Name: tc.resource, Namespaced: len(tc.namespace) != 0} |
| 194 | cl, srv, err := getClientServer(gv, func(w http.ResponseWriter, r *http.Request) { |
| 195 | if r.Method != "GET" { |
| 196 | t.Errorf("Get(%q) got HTTP method %s. wanted GET", tc.name, r.Method) |
| 197 | } |
| 198 | |
| 199 | if r.URL.Path != tc.path { |
| 200 | t.Errorf("Get(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path) |
| 201 | } |
| 202 | |
| 203 | w.Header().Set("Content-Type", runtime.ContentTypeJSON) |
| 204 | w.Write(tc.resp) |
| 205 | }) |
| 206 | if err != nil { |
| 207 | t.Errorf("unexpected error when creating client: %v", err) |
| 208 | continue |