(t *testing.T)
| 2037 | } |
| 2038 | |
| 2039 | func TestWatchFieldSelector(t *testing.T) { |
| 2040 | pods, events := watchTestData() |
| 2041 | |
| 2042 | tf := cmdtesting.NewTestFactory().WithNamespace("test") |
| 2043 | defer tf.Cleanup() |
| 2044 | codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) |
| 2045 | |
| 2046 | podList := &corev1.PodList{ |
| 2047 | Items: pods, |
| 2048 | ListMeta: metav1.ListMeta{ |
| 2049 | ResourceVersion: "10", |
| 2050 | }, |
| 2051 | } |
| 2052 | tf.UnstructuredClient = &fake.RESTClient{ |
| 2053 | NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, |
| 2054 | Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { |
| 2055 | if req.URL.Query().Get(metav1.FieldSelectorQueryParam("v1")) != "a=b" { |
| 2056 | t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) |
| 2057 | } |
| 2058 | switch req.URL.Path { |
| 2059 | case "/namespaces/test/pods": |
| 2060 | if req.URL.Query().Get("watch") == "true" { |
| 2061 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: watchBody(codec, events[2:])}, nil |
| 2062 | } |
| 2063 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, podList)}, nil |
| 2064 | default: |
| 2065 | t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) |
| 2066 | return nil, nil |
| 2067 | } |
| 2068 | }), |
| 2069 | } |
| 2070 | |
| 2071 | streams, _, buf, _ := genericiooptions.NewTestIOStreams() |
| 2072 | cmd := NewCmdGet("kubectl", tf, streams) |
| 2073 | cmd.SetOut(buf) |
| 2074 | cmd.SetErr(buf) |
| 2075 | |
| 2076 | cmd.Flags().Set("watch", "true") |
| 2077 | cmd.Flags().Set("field-selector", "a=b") |
| 2078 | cmd.Run(cmd, []string{"pods"}) |
| 2079 | |
| 2080 | expected := `NAME AGE |
| 2081 | bar <unknown> |
| 2082 | foo <unknown> |
| 2083 | foo <unknown> |
| 2084 | foo <unknown> |
| 2085 | ` |
| 2086 | if e, a := expected, buf.String(); e != a { |
| 2087 | t.Errorf("expected\n%v\ngot\n%v", e, a) |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | func TestWatchTableFieldSelector(t *testing.T) { |
| 2092 | pods, events := watchTestData() |
nothing calls this directly
no test coverage detected
searching dependent graphs…