update various commands to adapt the new Factory interface

This commit is contained in:
AdoHe
2016-10-13 08:18:39 +08:00
parent dfae1a27c2
commit b2280a646a
53 changed files with 154 additions and 200 deletions

View File

@@ -55,7 +55,7 @@ func TestPodAndContainer(t *testing.T) {
p *ExecOptions
name string
expectError bool
expectedPod *api.Pod
expectedPod string
expectedContainer string
expectedArgs []string
}{
@@ -81,18 +81,10 @@ func TestPodAndContainer(t *testing.T) {
p: &ExecOptions{StreamOptions: StreamOptions{PodName: "foo"}},
args: []string{"cmd"},
argsLenAtDash: -1,
expectedPod: execPod(),
expectedPod: "foo",
expectedArgs: []string{"cmd"},
name: "pod in flags",
},
{
p: &ExecOptions{StreamOptions: StreamOptions{PodName: "pod/foo"}},
args: []string{"cmd"},
argsLenAtDash: -1,
expectedPod: execPod(),
expectedArgs: []string{"cmd"},
name: "pod with 'pod/' prefix in flags",
},
{
p: &ExecOptions{},
args: []string{"foo", "cmd"},
@@ -111,23 +103,15 @@ func TestPodAndContainer(t *testing.T) {
p: &ExecOptions{},
args: []string{"foo", "cmd"},
argsLenAtDash: -1,
expectedPod: execPod(),
expectedPod: "foo",
expectedArgs: []string{"cmd"},
name: "cmd, w/o flags",
},
{
p: &ExecOptions{},
args: []string{"pod/foo", "cmd"},
argsLenAtDash: -1,
expectedPod: execPod(),
expectedArgs: []string{"cmd"},
name: "pod with 'pod/' prefix, cmd, w/o flags",
},
{
p: &ExecOptions{},
args: []string{"foo", "cmd"},
argsLenAtDash: 1,
expectedPod: execPod(),
expectedPod: "foo",
expectedArgs: []string{"cmd"},
name: "cmd, cmd is behind dash",
},
@@ -135,27 +119,17 @@ func TestPodAndContainer(t *testing.T) {
p: &ExecOptions{StreamOptions: StreamOptions{ContainerName: "bar"}},
args: []string{"foo", "cmd"},
argsLenAtDash: -1,
expectedPod: execPod(),
expectedPod: "foo",
expectedContainer: "bar",
expectedArgs: []string{"cmd"},
name: "cmd, container in flag",
},
}
for _, test := range tests {
f, tf, codec, ns := NewAPIFactory()
f, tf, _, ns := NewAPIFactory()
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch m := req.Method; {
case m == "GET":
body := objBody(codec, test.expectedPod)
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: body}, nil
default:
//Ensures no GET is performed when deleting by name
t.Errorf("%s: unexpected request: %s %#v\n%#v", test.name, req.Method, req.URL, req)
return nil, fmt.Errorf("unexpected request")
}
}),
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { return nil, nil }),
}
tf.Namespace = "test"
tf.ClientConfig = defaultClientConfig()
@@ -172,8 +146,8 @@ func TestPodAndContainer(t *testing.T) {
if err != nil {
continue
}
if options.PodName != test.expectedPod.Name {
t.Errorf("expected: %s, got: %s (%s)", test.expectedPod.Name, options.PodName, test.name)
if options.PodName != test.expectedPod {
t.Errorf("expected: %s, got: %s (%s)", test.expectedPod, options.PodName, test.name)
}
if options.ContainerName != test.expectedContainer {
t.Errorf("expected: %s, got: %s (%s)", test.expectedContainer, options.ContainerName, test.name)
@@ -187,24 +161,22 @@ func TestPodAndContainer(t *testing.T) {
func TestExec(t *testing.T) {
version := registered.GroupOrDie(api.GroupName).GroupVersion.Version
tests := []struct {
name, shortPodPath, podPath, execPath, container string
pod *api.Pod
execErr bool
name, podPath, execPath, container string
pod *api.Pod
execErr bool
}{
{
name: "pod exec",
shortPodPath: "/namespaces/test/pods/foo",
podPath: "/api/" + version + "/namespaces/test/pods/foo",
execPath: "/api/" + version + "/namespaces/test/pods/foo/exec",
pod: execPod(),
name: "pod exec",
podPath: "/api/" + version + "/namespaces/test/pods/foo",
execPath: "/api/" + version + "/namespaces/test/pods/foo/exec",
pod: execPod(),
},
{
name: "pod exec error",
shortPodPath: "/namespaces/test/pods/foo",
podPath: "/api/" + version + "/namespaces/test/pods/foo",
execPath: "/api/" + version + "/namespaces/test/pods/foo/exec",
pod: execPod(),
execErr: true,
name: "pod exec error",
podPath: "/api/" + version + "/namespaces/test/pods/foo",
execPath: "/api/" + version + "/namespaces/test/pods/foo/exec",
pod: execPod(),
execErr: true,
},
}
for _, test := range tests {
@@ -216,9 +188,6 @@ func TestExec(t *testing.T) {
case p == test.podPath && m == "GET":
body := objBody(codec, test.pod)
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: body}, nil
case p == test.shortPodPath && m == "GET":
body := objBody(codec, test.pod)
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: body}, nil
default:
// Ensures no GET is performed when deleting by name
t.Errorf("%s: unexpected request: %s %#v\n%#v", test.name, req.Method, req.URL, req)