make testclient more precise

This commit is contained in:
deads2k
2015-08-03 09:21:11 -04:00
parent 4271f28548
commit 182885e897
33 changed files with 1004 additions and 401 deletions

View File

@@ -682,8 +682,8 @@ func TestControllerUpdateRequeue(t *testing.T) {
func TestControllerUpdateStatusWithFailure(t *testing.T) {
rc := newReplicationController(1)
fakeClient := &testclient.Fake{
ReactFn: func(f testclient.FakeAction) (runtime.Object, error) {
if f.Action == testclient.GetControllerAction {
ReactFn: func(action testclient.Action) (runtime.Object, error) {
if action.GetVerb() == "get" && action.GetResource() == "replicationcontrollers" {
return rc, nil
}
return &api.ReplicationController{}, fmt.Errorf("Fake error")
@@ -694,18 +694,23 @@ func TestControllerUpdateStatusWithFailure(t *testing.T) {
updateReplicaCount(fakeRCClient, *rc, numReplicas)
updates, gets := 0, 0
for _, a := range fakeClient.Actions() {
switch a.Action {
case testclient.GetControllerAction:
if a.GetResource() != "replicationcontrollers" {
t.Errorf("Unexpected action %+v", a)
continue
}
switch action := a.(type) {
case testclient.GetAction:
gets++
// Make sure the get is for the right rc even though the update failed.
if s, ok := a.Value.(string); !ok || s != rc.Name {
t.Errorf("Expected get for rc %v, got %+v instead", rc.Name, s)
if action.GetName() != rc.Name {
t.Errorf("Expected get for rc %v, got %+v instead", rc.Name, action.GetName())
}
case testclient.UpdateControllerAction:
case testclient.UpdateAction:
updates++
// Confirm that the update has the right status.Replicas even though the Get
// returned an rc with replicas=1.
if c, ok := a.Value.(*api.ReplicationController); !ok {
if c, ok := action.GetObject().(*api.ReplicationController); !ok {
t.Errorf("Expected an rc as the argument to update, got %T", c)
} else if c.Status.Replicas != numReplicas {
t.Errorf("Expected update for rc to contain replicas %v, got %v instead",