Write to STDERR when Delete contains no resources

Also test that this occurs
This commit is contained in:
Clayton Coleman
2015-01-14 13:52:03 -05:00
parent 28555bb653
commit da2b03d8d8
2 changed files with 35 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ import (
"strings"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
@@ -82,6 +83,37 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
}
}
func TestDeleteNoObjects(t *testing.T) {
f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &client.FakeRESTClient{
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/ns/test/pods" && m == "GET":
return &http.Response{StatusCode: 200, Body: objBody(codec, &api.PodList{})}, nil
default:
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
return nil, nil
}
}),
}
buf := bytes.NewBuffer([]byte{})
stderr := bytes.NewBuffer([]byte{})
cmd := f.NewCmdDelete(buf)
cmd.SetOutput(stderr)
cmd.Flags().String("namespace", "test", "")
cmd.Run(cmd, []string{"pods"})
if buf.String() != "" {
t.Errorf("unexpected output: %s", buf.String())
}
if stderr.String() != "No resources found\n" {
t.Errorf("unexpected output: %s", stderr.String())
}
}
func TestDeleteMultipleObject(t *testing.T) {
pods, svc := testData()