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

Function TestDeleteCollection

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

Source from the content-addressed store, hash-verified

281}
282
283func TestDeleteCollection(t *testing.T) {
284 statusOK := &metav1.Status{
285 TypeMeta: metav1.TypeMeta{Kind: "Status"},
286 Status: metav1.StatusSuccess,
287 }
288 tcs := []struct {
289 namespace string
290 name string
291 path string
292 }{
293 {
294 name: "normal_delete_collection",
295 path: "/apis/gtest/vtest/rtest",
296 },
297 {
298 namespace: "nstest",
299 name: "namespaced_delete_collection",
300 path: "/apis/gtest/vtest/namespaces/nstest/rtest",
301 },
302 }
303 for _, tc := range tcs {
304 gv := &schema.GroupVersion{Group: "gtest", Version: "vtest"}
305 resource := &metav1.APIResource{Name: "rtest", Namespaced: len(tc.namespace) != 0}
306 cl, srv, err := getClientServer(gv, func(w http.ResponseWriter, r *http.Request) {
307 if r.Method != "DELETE" {
308 t.Errorf("DeleteCollection(%q) got HTTP method %s. wanted DELETE", tc.name, r.Method)
309 }
310
311 if r.URL.Path != tc.path {
312 t.Errorf("DeleteCollection(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path)
313 }
314
315 w.Header().Set("Content-Type", runtime.ContentTypeJSON)
316 unstructured.UnstructuredJSONScheme.Encode(statusOK, w)
317 })
318 if err != nil {
319 t.Errorf("unexpected error when creating client: %v", err)
320 continue
321 }
322 defer srv.Close()
323
324 err = cl.Resource(resource, tc.namespace).DeleteCollection(nil, metav1.ListOptions{})
325 if err != nil {
326 t.Errorf("unexpected error when deleting collection %q: %v", tc.name, err)
327 continue
328 }
329 }
330}
331
332func TestCreate(t *testing.T) {
333 tcs := []struct {

Callers

nothing calls this directly

Calls 7

getClientServerFunction · 0.70
ErrorfMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
DeleteCollectionMethod · 0.65
ResourceMethod · 0.65
EncodeMethod · 0.45

Tested by

no test coverage detected