(t *testing.T)
| 494 | } |
| 495 | |
| 496 | func TestWatch(t *testing.T) { |
| 497 | tcs := []struct { |
| 498 | name string |
| 499 | namespace string |
| 500 | events []watch.Event |
| 501 | path string |
| 502 | query string |
| 503 | }{ |
| 504 | { |
| 505 | name: "normal_watch", |
| 506 | path: "/apis/gtest/vtest/rtest", |
| 507 | query: "watch=true", |
| 508 | events: []watch.Event{ |
| 509 | {Type: watch.Added, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 510 | {Type: watch.Modified, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 511 | {Type: watch.Deleted, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 512 | }, |
| 513 | }, |
| 514 | { |
| 515 | name: "namespaced_watch", |
| 516 | namespace: "nstest", |
| 517 | path: "/apis/gtest/vtest/namespaces/nstest/rtest", |
| 518 | query: "watch=true", |
| 519 | events: []watch.Event{ |
| 520 | {Type: watch.Added, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 521 | {Type: watch.Modified, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 522 | {Type: watch.Deleted, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 523 | }, |
| 524 | }, |
| 525 | } |
| 526 | for _, tc := range tcs { |
| 527 | resource := schema.GroupVersionResource{Group: "gtest", Version: "vtest", Resource: "rtest"} |
| 528 | cl, srv, err := getClientServer(func(w http.ResponseWriter, r *http.Request) { |
| 529 | if r.Method != "GET" { |
| 530 | t.Errorf("Watch(%q) got HTTP method %s. wanted GET", tc.name, r.Method) |
| 531 | } |
| 532 | |
| 533 | if r.URL.Path != tc.path { |
| 534 | t.Errorf("Watch(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path) |
| 535 | } |
| 536 | if r.URL.RawQuery != tc.query { |
| 537 | t.Errorf("Watch(%q) got query %s. wanted %s", tc.name, r.URL.RawQuery, tc.query) |
| 538 | } |
| 539 | |
| 540 | enc := restclientwatch.NewEncoder(streaming.NewEncoder(w, unstructured.UnstructuredJSONScheme), unstructured.UnstructuredJSONScheme) |
| 541 | for _, e := range tc.events { |
| 542 | enc.Encode(&e) |
| 543 | } |
| 544 | }) |
| 545 | if err != nil { |
| 546 | t.Errorf("unexpected error when creating client: %v", err) |
| 547 | continue |
| 548 | } |
| 549 | defer srv.Close() |
| 550 | |
| 551 | watcher, err := cl.Resource(resource).Namespace(tc.namespace).Watch(metav1.ListOptions{}) |
| 552 | if err != nil { |
| 553 | t.Errorf("unexpected error when watching %q: %v", tc.name, err) |
nothing calls this directly
no test coverage detected