Merge pull request #10783 from mikedanese/make-test-client-threadsafe
make testclient threadsafe by guarding internal state with accessors
This commit is contained in:
@@ -74,19 +74,19 @@ func (c *fakeRc) Get(name string) (*api.ReplicationController, error) {
|
||||
if len(c.responses) == 0 {
|
||||
return nil, fmt.Errorf("Unexpected Action: %s", action)
|
||||
}
|
||||
c.Fake.Actions = append(c.Fake.Actions, action)
|
||||
c.Fake.Invokes(action, nil)
|
||||
result := c.responses[0]
|
||||
c.responses = c.responses[1:]
|
||||
return result.controller, result.err
|
||||
}
|
||||
|
||||
func (c *fakeRc) Create(controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, testclient.FakeAction{Action: "create-controller", Value: controller.ObjectMeta.Name})
|
||||
c.Fake.Invokes(testclient.FakeAction{Action: "create-controller", Value: controller.ObjectMeta.Name}, nil)
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
func (c *fakeRc) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, testclient.FakeAction{Action: "update-controller", Value: controller.ObjectMeta.Name})
|
||||
c.Fake.Invokes(testclient.FakeAction{Action: "update-controller", Value: controller.ObjectMeta.Name}, nil)
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
|
@@ -73,14 +73,15 @@ func TestReplicationControllerScale(t *testing.T) {
|
||||
name := "foo"
|
||||
scaler.Scale("default", name, count, &preconditions, nil, nil)
|
||||
|
||||
if len(fake.Actions) != 2 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", fake.Actions)
|
||||
actions := fake.Actions()
|
||||
if len(actions) != 2 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
|
||||
}
|
||||
if fake.Actions[0].Action != "get-replicationController" || fake.Actions[0].Value != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", fake.Actions[0], name)
|
||||
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
|
||||
}
|
||||
if fake.Actions[1].Action != "update-replicationController" || fake.Actions[1].Value.(*api.ReplicationController).Spec.Replicas != int(count) {
|
||||
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", fake.Actions[1], count)
|
||||
if actions[1].Action != "update-replicationController" || actions[1].Value.(*api.ReplicationController).Spec.Replicas != int(count) {
|
||||
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", actions[1], count)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +97,12 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
|
||||
name := "foo"
|
||||
scaler.Scale("default", name, count, &preconditions, nil, nil)
|
||||
|
||||
if len(fake.Actions) != 1 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", fake.Actions)
|
||||
actions := fake.Actions()
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
|
||||
}
|
||||
if fake.Actions[0].Action != "get-replicationController" || fake.Actions[0].Value != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", fake.Actions[0], name)
|
||||
if actions[0].Action != "get-replicationController" || actions[0].Value != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -47,12 +47,13 @@ func TestReplicationControllerStop(t *testing.T) {
|
||||
if s != expected {
|
||||
t.Errorf("expected %s, got %s", expected, s)
|
||||
}
|
||||
if len(fake.Actions) != 7 {
|
||||
actions := fake.Actions()
|
||||
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 fake.Actions[i].Action != action+"-replicationController" {
|
||||
t.Errorf("unexpected action: %+v, expected %s-replicationController", fake.Actions[i], action)
|
||||
if actions[i].Action != action+"-replicationController" {
|
||||
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], action)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,10 +160,11 @@ func TestSimpleStop(t *testing.T) {
|
||||
t.Errorf("unexpected return: %s (%s)", s, test.test)
|
||||
}
|
||||
}
|
||||
if len(test.actions) != len(fake.Actions) {
|
||||
actions := fake.Actions()
|
||||
if len(test.actions) != len(actions) {
|
||||
t.Errorf("unexpected actions: %v; expected %v (%s)", fake.Actions, test.actions, test.test)
|
||||
}
|
||||
for i, action := range fake.Actions {
|
||||
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)
|
||||
|
Reference in New Issue
Block a user