(t *testing.T)
| 1933 | } |
| 1934 | |
| 1935 | func TestWatchLabelSelector(t *testing.T) { |
| 1936 | pods, events := watchTestData() |
| 1937 | |
| 1938 | tf := cmdtesting.NewTestFactory().WithNamespace("test") |
| 1939 | defer tf.Cleanup() |
| 1940 | codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) |
| 1941 | |
| 1942 | podList := &corev1.PodList{ |
| 1943 | Items: pods, |
| 1944 | ListMeta: metav1.ListMeta{ |
| 1945 | ResourceVersion: "10", |
| 1946 | }, |
| 1947 | } |
| 1948 | tf.UnstructuredClient = &fake.RESTClient{ |
| 1949 | NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, |
| 1950 | Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { |
| 1951 | if req.URL.Query().Get(metav1.LabelSelectorQueryParam("v1")) != "a=b" { |
| 1952 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 1953 | } |
| 1954 | switch req.URL.Path { |
| 1955 | case "/namespaces/test/pods": |
| 1956 | if req.URL.Query().Get("watch") == "true" { |
| 1957 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: watchBody(codec, events[2:])}, nil |
| 1958 | } |
| 1959 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, podList)}, nil |
| 1960 | default: |
| 1961 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 1962 | return nil, nil |
| 1963 | } |
| 1964 | }), |
| 1965 | } |
| 1966 | |
| 1967 | streams, _, buf, _ := genericiooptions.NewTestIOStreams() |
| 1968 | cmd := NewCmdGet("kubectl", tf, streams) |
| 1969 | cmd.SetOut(buf) |
| 1970 | cmd.SetErr(buf) |
| 1971 | |
| 1972 | cmd.Flags().Set("watch", "true") |
| 1973 | cmd.Flags().Set("selector", "a=b") |
| 1974 | cmd.Run(cmd, []string{"pods"}) |
| 1975 | |
| 1976 | expected := `NAME AGE |
| 1977 | bar <unknown> |
| 1978 | foo <unknown> |
| 1979 | foo <unknown> |
| 1980 | foo <unknown> |
| 1981 | ` |
| 1982 | if e, a := expected, buf.String(); e != a { |
| 1983 | t.Errorf("expected\n%v\ngot\n%v", e, a) |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | func TestWatchTableLabelSelector(t *testing.T) { |
| 1988 | pods, events := watchTestData() |
nothing calls this directly
no test coverage detected
searching dependent graphs…