mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-16 19:57:02 +00:00
make testclient threadsafe by guarding internal state with accessors
This commit is contained in:
@@ -53,13 +53,14 @@ func TestFinalize(t *testing.T) {
|
||||
},
|
||||
}
|
||||
finalize(mockClient, testNamespace)
|
||||
if len(mockClient.Actions) != 1 {
|
||||
t.Errorf("Expected 1 mock client action, but got %v", len(mockClient.Actions))
|
||||
actions := mockClient.Actions()
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("Expected 1 mock client action, but got %v", len(actions))
|
||||
}
|
||||
if mockClient.Actions[0].Action != "finalize-namespace" {
|
||||
t.Errorf("Expected finalize-namespace action %v", mockClient.Actions[0].Action)
|
||||
if actions[0].Action != "finalize-namespace" {
|
||||
t.Errorf("Expected finalize-namespace action %v", actions[0].Action)
|
||||
}
|
||||
finalizers := mockClient.Actions[0].Value.(*api.Namespace).Spec.Finalizers
|
||||
finalizers := actions[0].Value.(*api.Namespace).Spec.Finalizers
|
||||
if len(finalizers) != 1 {
|
||||
t.Errorf("There should be a single finalizer remaining")
|
||||
}
|
||||
@@ -100,8 +101,8 @@ func TestSyncNamespaceThatIsTerminating(t *testing.T) {
|
||||
"finalize-namespace",
|
||||
"delete-namespace")
|
||||
actionSet := util.NewStringSet()
|
||||
for i := range mockClient.Actions {
|
||||
actionSet.Insert(mockClient.Actions[i].Action)
|
||||
for _, action := range mockClient.Actions() {
|
||||
actionSet.Insert(action.Action)
|
||||
}
|
||||
if !actionSet.HasAll(expectedActionSet.List()...) {
|
||||
t.Errorf("Expected actions: %v, but got: %v", expectedActionSet, actionSet)
|
||||
@@ -127,8 +128,8 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
|
||||
t.Errorf("Unexpected error when synching namespace %v", err)
|
||||
}
|
||||
actionSet := util.NewStringSet()
|
||||
for i := range mockClient.Actions {
|
||||
actionSet.Insert(mockClient.Actions[i].Action)
|
||||
for _, action := range mockClient.Actions() {
|
||||
actionSet.Insert(action.Action)
|
||||
}
|
||||
if len(actionSet) != 0 {
|
||||
t.Errorf("Expected no action from controller, but got: %v", actionSet)
|
||||
|
||||
Reference in New Issue
Block a user