make testclient more precise
This commit is contained in:
@@ -70,7 +70,7 @@ type fakeRc struct {
|
||||
}
|
||||
|
||||
func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
|
||||
action := testclient.FakeAction{Action: "get-controller", Value: name}
|
||||
action := testclient.NewGetAction("replicationcontrollers", "", name)
|
||||
if len(c.responses) == 0 {
|
||||
return nil, fmt.Errorf("Unexpected Action: %s", action)
|
||||
}
|
||||
@@ -81,12 +81,12 @@ func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
|
||||
}
|
||||
|
||||
func (c *fakeRc) Create(controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||
c.Fake.Invokes(testclient.FakeAction{Action: "create-controller", Value: controller.ObjectMeta.Name}, nil)
|
||||
c.Fake.Invokes(testclient.NewCreateAction("replicationcontrollers", controller.Namespace, controller), nil)
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
func (c *fakeRc) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||
c.Fake.Invokes(testclient.FakeAction{Action: "update-controller", Value: controller.ObjectMeta.Name}, nil)
|
||||
c.Fake.Invokes(testclient.NewUpdateAction("replicationcontrollers", controller.Namespace, controller), nil)
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
|
@@ -77,10 +77,10 @@ func TestReplicationControllerScale(t *testing.T) {
|
||||
if len(actions) != 2 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
|
||||
}
|
||||
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
|
||||
}
|
||||
if actions[1].Action != "update-replicationController" || actions[1].Value.(*api.ReplicationController).Spec.Replicas != int(count) {
|
||||
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetObject().(*api.ReplicationController).Spec.Replicas != int(count) {
|
||||
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", actions[1], count)
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
|
||||
}
|
||||
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
|
||||
}
|
||||
}
|
||||
|
@@ -51,9 +51,13 @@ func TestReplicationControllerStop(t *testing.T) {
|
||||
if len(actions) != 7 {
|
||||
t.Errorf("unexpected actions: %v, expected 6 actions (get, list, get, update, get, get, delete)", fake.Actions)
|
||||
}
|
||||
for i, action := range []string{"get", "list", "get", "update", "get", "get", "delete"} {
|
||||
if actions[i].Action != action+"-replicationController" {
|
||||
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], action)
|
||||
for i, verb := range []string{"get", "list", "get", "update", "get", "get", "delete"} {
|
||||
if actions[i].GetResource() != "replicationcontrollers" {
|
||||
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
|
||||
continue
|
||||
}
|
||||
if actions[i].GetVerb() != verb {
|
||||
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +103,7 @@ func TestSimpleStop(t *testing.T) {
|
||||
tests := []struct {
|
||||
fake *reaperFake
|
||||
kind string
|
||||
actions []string
|
||||
actions []testclient.Action
|
||||
expectError bool
|
||||
test string
|
||||
}{
|
||||
@@ -107,8 +111,11 @@ func TestSimpleStop(t *testing.T) {
|
||||
fake: &reaperFake{
|
||||
Fake: &testclient.Fake{},
|
||||
},
|
||||
kind: "Pod",
|
||||
actions: []string{"get-pod", "delete-pod"},
|
||||
kind: "Pod",
|
||||
actions: []testclient.Action{
|
||||
testclient.NewGetAction("pods", api.NamespaceDefault, "foo"),
|
||||
testclient.NewDeleteAction("pods", api.NamespaceDefault, "foo"),
|
||||
},
|
||||
expectError: false,
|
||||
test: "stop pod succeeds",
|
||||
},
|
||||
@@ -116,8 +123,11 @@ func TestSimpleStop(t *testing.T) {
|
||||
fake: &reaperFake{
|
||||
Fake: &testclient.Fake{},
|
||||
},
|
||||
kind: "Service",
|
||||
actions: []string{"get-service", "delete-service"},
|
||||
kind: "Service",
|
||||
actions: []testclient.Action{
|
||||
testclient.NewGetAction("services", api.NamespaceDefault, "foo"),
|
||||
testclient.NewDeleteAction("services", api.NamespaceDefault, "foo"),
|
||||
},
|
||||
expectError: false,
|
||||
test: "stop service succeeds",
|
||||
},
|
||||
@@ -127,7 +137,7 @@ func TestSimpleStop(t *testing.T) {
|
||||
noSuchPod: true,
|
||||
},
|
||||
kind: "Pod",
|
||||
actions: []string{},
|
||||
actions: []testclient.Action{},
|
||||
expectError: true,
|
||||
test: "stop pod fails, no pod",
|
||||
},
|
||||
@@ -136,8 +146,10 @@ func TestSimpleStop(t *testing.T) {
|
||||
Fake: &testclient.Fake{},
|
||||
noDeleteService: true,
|
||||
},
|
||||
kind: "Service",
|
||||
actions: []string{"get-service"},
|
||||
kind: "Service",
|
||||
actions: []testclient.Action{
|
||||
testclient.NewGetAction("services", api.NamespaceDefault, "foo"),
|
||||
},
|
||||
expectError: true,
|
||||
test: "stop service fails, can't delete",
|
||||
},
|
||||
@@ -166,8 +178,8 @@ func TestSimpleStop(t *testing.T) {
|
||||
}
|
||||
for i, action := range actions {
|
||||
testAction := test.actions[i]
|
||||
if action.Action != testAction {
|
||||
t.Errorf("unexpected action: %v; expected %v (%s)", action, testAction, test.test)
|
||||
if action != testAction {
|
||||
t.Errorf("unexpected action: %#v; expected %v (%s)", action, testAction, test.test)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user