Kubectl expose command accepts a filename param
This commit is contained in:
@@ -202,7 +202,6 @@ func TestRunExposeService(t *testing.T) {
|
||||
cmd.Flags().Set(flag, value)
|
||||
}
|
||||
cmd.Run(cmd, test.args)
|
||||
|
||||
if len(test.expected) > 0 {
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, test.expected) {
|
||||
@@ -211,3 +210,76 @@ func TestRunExposeService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunExposeServiceFromFile(t *testing.T) {
|
||||
test := struct {
|
||||
calls map[string]string
|
||||
input runtime.Object
|
||||
flags map[string]string
|
||||
output runtime.Object
|
||||
expected string
|
||||
status int
|
||||
}{
|
||||
calls: map[string]string{
|
||||
"GET": "/namespaces/test/services/redis-master",
|
||||
"POST": "/namespaces/test/services",
|
||||
},
|
||||
input: &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
TypeMeta: api.TypeMeta{Kind: "Service", APIVersion: "v1"},
|
||||
Spec: api.ServiceSpec{
|
||||
Selector: map[string]string{"app": "go"},
|
||||
},
|
||||
},
|
||||
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test"},
|
||||
output: &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "test", ResourceVersion: "12", Labels: map[string]string{"svc": "test"}},
|
||||
TypeMeta: api.TypeMeta{Kind: "Service", APIVersion: "v1"},
|
||||
Spec: api.ServiceSpec{
|
||||
Ports: []api.ServicePort{
|
||||
{
|
||||
Name: "default",
|
||||
Protocol: api.Protocol("UDP"),
|
||||
Port: 14,
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{"func": "stream"},
|
||||
},
|
||||
},
|
||||
status: 200,
|
||||
}
|
||||
|
||||
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 == test.calls[m] && m == "GET":
|
||||
return &http.Response{StatusCode: test.status, Body: objBody(codec, test.input)}, nil
|
||||
case p == test.calls[m] && m == "POST":
|
||||
return &http.Response{StatusCode: test.status, Body: objBody(codec, test.output)}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||
return nil, nil
|
||||
}
|
||||
}),
|
||||
}
|
||||
tf.Namespace = "test"
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
cmd := NewCmdExposeService(f, buf)
|
||||
cmd.SetOutput(buf)
|
||||
|
||||
for flag, value := range test.flags {
|
||||
cmd.Flags().Set(flag, value)
|
||||
}
|
||||
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-service.yaml")
|
||||
cmd.Run(cmd, []string{})
|
||||
if len(test.expected) > 0 {
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, test.expected) {
|
||||
t.Errorf("unexpected output: %s", out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user