make testclient threadsafe by guarding internal state with accessors

This commit is contained in:
Mike Danese
2015-07-06 14:37:46 -07:00
parent 59611d7160
commit 1b84fb7d74
28 changed files with 151 additions and 99 deletions

View File

@@ -45,10 +45,11 @@ func TestAdmission(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error returned from admission handler")
}
if len(mockClient.Actions) != 1 {
actions := mockClient.Actions()
if len(actions) != 1 {
t.Errorf("Expected a create-namespace request")
}
if mockClient.Actions[0].Action != "create-namespace" {
if actions[0].Action != "create-namespace" {
t.Errorf("Expected a create-namespace request to be made via the client")
}
}
@@ -76,7 +77,7 @@ func TestAdmissionNamespaceExists(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error returned from admission handler")
}
if len(mockClient.Actions) != 0 {
if len(mockClient.Actions()) != 0 {
t.Errorf("No client request should have been made")
}
}
@@ -97,7 +98,7 @@ func TestIgnoreAdmission(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error returned from admission handler")
}
if len(mockClient.Actions) != 0 {
if len(mockClient.Actions()) != 0 {
t.Errorf("No client request should have been made")
}
}
@@ -105,9 +106,9 @@ func TestIgnoreAdmission(t *testing.T) {
// TestAdmissionNamespaceExistsUnknownToHandler
func TestAdmissionNamespaceExistsUnknownToHandler(t *testing.T) {
namespace := "test"
mockClient := &testclient.Fake{
Err: errors.NewAlreadyExists("namespaces", namespace),
}
mockClient := &testclient.Fake{}
mockClient.SetErr(errors.NewAlreadyExists("namespaces", namespace))
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
handler := &provision{
client: mockClient,