Kubectl get command accepts a filename param

This commit is contained in:
feihujiang
2015-08-10 19:02:14 +08:00
parent a6148e79c3
commit 18a1400928
6 changed files with 107 additions and 9 deletions

View File

@@ -275,6 +275,33 @@ func TestGetObjects(t *testing.T) {
}
}
func TestGetObjectsIdentifiedByFile(t *testing.T) {
pods, _, _ := testData()
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &pods.Items[0])},
}
tf.Namespace = "test"
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdGet(f, buf)
cmd.SetOutput(buf)
cmd.Flags().Set("filename", "../../../examples/cassandra/cassandra.yaml")
cmd.Run(cmd, []string{})
expected := []runtime.Object{&pods.Items[0]}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
}
func TestGetListObjects(t *testing.T) {
pods, _, _ := testData()
@@ -635,6 +662,45 @@ func TestWatchResource(t *testing.T) {
}
}
func TestWatchResourceIdentifiedByFile(t *testing.T) {
pods, events := watchTestData()
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/cassandra":
return &http.Response{StatusCode: 200, Body: objBody(codec, &pods[0])}, nil
case "/watch/namespaces/test/pods/cassandra":
return &http.Response{StatusCode: 200, Body: watchBody(codec, events)}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
return nil, nil
}
}),
}
tf.Namespace = "test"
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdGet(f, buf)
cmd.SetOutput(buf)
cmd.Flags().Set("watch", "true")
cmd.Flags().Set("filename", "../../../examples/cassandra/cassandra.yaml")
cmd.Run(cmd, []string{})
expected := []runtime.Object{&pods[0], events[0].Object, events[1].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("expected object: %#v unexpected object: %#v", expected, actual)
}
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
}
func TestWatchOnlyResource(t *testing.T) {
pods, events := watchTestData()