fixes testSyncNamespaceThatIsTerminating
@@ -137,6 +137,7 @@ func testSyncNamespaceThatIsTerminating(t *testing.T) {
dynamicClientActionSet sets.String
expectErrorOnDelete error
expectStatus *v1.NamespaceStatus
+ gvrError error
}{
"pending-finalize": {
testNamespace: testNamespacePendingFinalize,
@@ -144,7 +145,6 @@ func testSyncNamespaceThatIsTerminating(t *testing.T) {
strings.Join([]string{"get", "namespaces", ""}, "-"),
strings.Join([]string{"create", "namespaces", "finalize"}, "-"),
strings.Join([]string{"list", "pods", ""}, "-"),
- strings.Join([]string{"update", "namespaces", ""}, "-"),
strings.Join([]string{"delete", "namespaces", ""}, "-"),
),
dynamicClientActionSet: dynamicClientActionSet,
@@ -172,7 +172,7 @@ func testSyncNamespaceThatIsTerminating(t *testing.T) {
strings.Join([]string{"list", "pods", ""}, "-"),
strings.Join([]string{"update", "namespaces", "status"}, "-"),
),
- metadataClientActionSet: metadataClientActionSet,
+ dynamicClientActionSet: dynamicClientActionSet,
gvrError: fmt.Errorf("test error"),
expectErrorOnDelete: fmt.Errorf("test error"),
expectStatus: &v1.NamespaceStatus{
@@ -226,19 +226,16 @@ func testSyncNamespaceThatIsTerminating(t *testing.T) {
// validate status conditions
if testInput.expectStatus != nil {
- obj, err := mockClient.Tracker().Get(schema.GroupVersionResource{Version: "v1", Resource: "namespaces"}, testInput.testNamespace.Namespace, testInput.testNamespace.Name)
- if err != nil {
- t.Errorf("Unexpected error in getting the namespace: %v", err)
- continue
- }
+ wasStatusValidated := false
+ for _, action := range mockClient.Actions() {
+ if action.Matches("update", "namespaces") {
+ obj := action.(core.UpdateAction).GetObject()
ns, ok := obj.(*v1.Namespace)
if !ok {
- t.Errorf("Expected a namespace but received %v", obj)
- continue
+ t.Fatalf("Expected a namespace but received %v", obj)
}
if ns.Status.Phase != testInput.expectStatus.Phase {
- t.Errorf("Expected namespace status phase %v but received %v", testInput.expectStatus.Phase, ns.Status.Phase)
- continue
+ t.Fatalf("Expected namespace status phase %v but received %v", testInput.expectStatus.Phase, ns.Status.Phase)
}
for _, expCondition := range testInput.expectStatus.Conditions {
nsCondition := getCondition(ns.Status.Conditions, expCondition.Type)
@@ -247,6 +244,13 @@ func testSyncNamespaceThatIsTerminating(t *testing.T) {
continue
}
}
+ wasStatusValidated = true
+ break
+ }
+ }
+ if !wasStatusValidated {
+ t.Fatal("the test expected to validate the status but it wasn't validated")
+ }
}
})
}
