(t *testing.T)
| 467 | } |
| 468 | |
| 469 | func TestWatch(t *testing.T) { |
| 470 | tcs := []struct { |
| 471 | name string |
| 472 | namespace string |
| 473 | events []watch.Event |
| 474 | path string |
| 475 | query string |
| 476 | }{ |
| 477 | { |
| 478 | name: "normal_watch", |
| 479 | path: "/apis/gtest/vtest/rtest", |
| 480 | query: "watch=true", |
| 481 | events: []watch.Event{ |
| 482 | {Type: watch.Added, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 483 | {Type: watch.Modified, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 484 | {Type: watch.Deleted, Object: getObject("gtest/vTest", "rTest", "normal_watch")}, |
| 485 | }, |
| 486 | }, |
| 487 | { |
| 488 | name: "namespaced_watch", |
| 489 | namespace: "nstest", |
| 490 | path: "/apis/gtest/vtest/namespaces/nstest/rtest", |
| 491 | query: "watch=true", |
| 492 | events: []watch.Event{ |
| 493 | {Type: watch.Added, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 494 | {Type: watch.Modified, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 495 | {Type: watch.Deleted, Object: getObject("gtest/vTest", "rTest", "namespaced_watch")}, |
| 496 | }, |
| 497 | }, |
| 498 | } |
| 499 | for _, tc := range tcs { |
| 500 | gv := &schema.GroupVersion{Group: "gtest", Version: "vtest"} |
| 501 | resource := &metav1.APIResource{Name: "rtest", Namespaced: len(tc.namespace) != 0} |
| 502 | cl, srv, err := getClientServer(gv, func(w http.ResponseWriter, r *http.Request) { |
| 503 | if r.Method != "GET" { |
| 504 | t.Errorf("Watch(%q) got HTTP method %s. wanted GET", tc.name, r.Method) |
| 505 | } |
| 506 | |
| 507 | if r.URL.Path != tc.path { |
| 508 | t.Errorf("Watch(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path) |
| 509 | } |
| 510 | if r.URL.RawQuery != tc.query { |
| 511 | t.Errorf("Watch(%q) got query %s. wanted %s", tc.name, r.URL.RawQuery, tc.query) |
| 512 | } |
| 513 | |
| 514 | enc := restclientwatch.NewEncoder(streaming.NewEncoder(w, dynamicCodec{}), dynamicCodec{}) |
| 515 | for _, e := range tc.events { |
| 516 | enc.Encode(&e) |
| 517 | } |
| 518 | }) |
| 519 | if err != nil { |
| 520 | t.Errorf("unexpected error when creating client: %v", err) |
| 521 | continue |
| 522 | } |
| 523 | defer srv.Close() |
| 524 | |
| 525 | watcher, err := cl.Resource(resource, tc.namespace).Watch(metav1.ListOptions{}) |
| 526 | if err != nil { |
nothing calls this directly
no test coverage detected