(t *testing.T)
| 1985 | } |
| 1986 | |
| 1987 | func TestWatchTableLabelSelector(t *testing.T) { |
| 1988 | pods, events := watchTestData() |
| 1989 | |
| 1990 | tf := cmdtesting.NewTestFactory().WithNamespace("test") |
| 1991 | defer tf.Cleanup() |
| 1992 | codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) |
| 1993 | |
| 1994 | podList := &corev1.PodList{ |
| 1995 | Items: pods, |
| 1996 | ListMeta: metav1.ListMeta{ |
| 1997 | ResourceVersion: "10", |
| 1998 | }, |
| 1999 | } |
| 2000 | tf.UnstructuredClient = &fake.RESTClient{ |
| 2001 | NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, |
| 2002 | Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { |
| 2003 | if req.URL.Query().Get(metav1.LabelSelectorQueryParam("v1")) != "a=b" { |
| 2004 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 2005 | } |
| 2006 | switch req.URL.Path { |
| 2007 | case "/namespaces/test/pods": |
| 2008 | if req.URL.Query().Get("watch") == "true" { |
| 2009 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableWatchBody(codec, events[2:])}, nil |
| 2010 | } |
| 2011 | return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, podList.Items...)}, nil |
| 2012 | default: |
| 2013 | t.Fatalf("request url: %#v,and request: %#v", req.URL, req) |
| 2014 | return nil, nil |
| 2015 | } |
| 2016 | }), |
| 2017 | } |
| 2018 | |
| 2019 | streams, _, buf, _ := genericiooptions.NewTestIOStreams() |
| 2020 | cmd := NewCmdGet("kubectl", tf, streams) |
| 2021 | cmd.SetOut(buf) |
| 2022 | cmd.SetErr(buf) |
| 2023 | |
| 2024 | cmd.Flags().Set("watch", "true") |
| 2025 | cmd.Flags().Set("selector", "a=b") |
| 2026 | cmd.Run(cmd, []string{"pods"}) |
| 2027 | |
| 2028 | expected := `NAME READY STATUS RESTARTS AGE |
| 2029 | bar 0/0 0 <unknown> |
| 2030 | foo 0/0 0 <unknown> |
| 2031 | foo 0/0 0 <unknown> |
| 2032 | foo 0/0 0 <unknown> |
| 2033 | ` |
| 2034 | if e, a := expected, buf.String(); e != a { |
| 2035 | t.Errorf("expected\n%v\ngot\n%v", e, a) |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | func TestWatchFieldSelector(t *testing.T) { |
| 2040 | pods, events := watchTestData() |
nothing calls this directly
no test coverage detected
searching dependent graphs…