(t *testing.T)
| 2141 | } |
| 2142 | |
| 2143 | func TestWatchResource(t *testing.T) { |
| 2144 | pods, events := watchTestData() |
| 2145 | |
| 2146 | tf := cmdtesting.NewTestFactory().WithNamespace("test") |
| 2147 | defer tf.Cleanup() |
| 2148 | codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) |
| 2149 | |
| 2150 | tf.UnstructuredClient = &fake.RESTClient{ |
| 2151 | NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, |
| 2152 | Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { |
| 2153 | switch req.URL.Path { |
| 2154 | case "/namespaces/test/pods/foo": |
| 2155 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods[1])}, nil |
| 2156 | case "/namespaces/test/pods": |
| 2157 | if req.URL.Query().Get("watch") == "true" && req.URL.Query().Get("fieldSelector") == "metadata.name=foo" { |
| 2158 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: watchBody(codec, events[1:])}, nil |
| 2159 | } |
| 2160 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 2161 | return nil, nil |
| 2162 | default: |
| 2163 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 2164 | return nil, nil |
| 2165 | } |
| 2166 | }), |
| 2167 | } |
| 2168 | |
| 2169 | streams, _, buf, _ := genericiooptions.NewTestIOStreams() |
| 2170 | cmd := NewCmdGet("kubectl", tf, streams) |
| 2171 | cmd.SetOut(buf) |
| 2172 | cmd.SetErr(buf) |
| 2173 | |
| 2174 | cmd.Flags().Set("watch", "true") |
| 2175 | cmd.Run(cmd, []string{"pods", "foo"}) |
| 2176 | |
| 2177 | expected := `NAME AGE |
| 2178 | foo <unknown> |
| 2179 | foo <unknown> |
| 2180 | foo <unknown> |
| 2181 | ` |
| 2182 | if e, a := expected, buf.String(); e != a { |
| 2183 | t.Errorf("expected\n%v\ngot\n%v", e, a) |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | func TestWatchNonExistObject(t *testing.T) { |
| 2188 | pods, _ := watchTestData() |
nothing calls this directly
no test coverage detected
searching dependent graphs…