diff --git a/internal/terraform/context_apply_action_test.go b/internal/terraform/context_apply_action_test.go index 90e895d0f0..90f66e87c2 100644 --- a/internal/terraform/context_apply_action_test.go +++ b/internal/terraform/context_apply_action_test.go @@ -31,8 +31,9 @@ func TestContext2Apply_actions(t *testing.T) { planOpts *PlanOpts - expectInvokeActionCalled bool - expectInvokeActionCalls []providers.InvokeActionRequest + expectInvokeActionCalled bool + expectInvokeActionCalls []providers.InvokeActionRequest + expectInvokeActionCallsAreUnordered bool expectDiagnostics func(m *configs.Config) tfdiags.Diagnostics }{ @@ -1277,7 +1278,8 @@ resource "test_object" "resource" { } `, }, - expectInvokeActionCalled: true, + expectInvokeActionCalled: true, + expectInvokeActionCallsAreUnordered: true, // The order depends on the order of the modules expectInvokeActionCalls: []providers.InvokeActionRequest{{ ActionType: "act_unlinked", PlannedActionData: cty.ObjectVal(map[string]cty.Value{ @@ -1425,14 +1427,30 @@ resource "test_object" "resource" { if len(tc.expectInvokeActionCalls) > 0 && len(invokeActionCalls) != len(tc.expectInvokeActionCalls) { t.Fatalf("expected %d invoke action calls, got %d", len(tc.expectInvokeActionCalls), len(invokeActionCalls)) } + for i, expectedCall := range tc.expectInvokeActionCalls { - actualCall := invokeActionCalls[i] + if tc.expectInvokeActionCallsAreUnordered { + // We established the length is correct, so we just need to find one call that matches for each + found := false + for _, actualCall := range invokeActionCalls { + if actualCall.ActionType == expectedCall.ActionType && actualCall.PlannedActionData.RawEquals(expectedCall.PlannedActionData) { + found = true + break + } + } + if !found { + t.Fatalf("expected invoke action call with ActionType %s and PlannedActionData %s was not found in actual calls", expectedCall.ActionType, expectedCall.PlannedActionData.GoString()) + } + } else { + // Expect correct order + actualCall := invokeActionCalls[i] - if actualCall.ActionType != expectedCall.ActionType { - t.Fatalf("expected invoke action call %d ActionType to be %s, got %s", i, expectedCall.ActionType, actualCall.ActionType) - } - if !actualCall.PlannedActionData.RawEquals(expectedCall.PlannedActionData) { - t.Fatalf("expected invoke action call %d PlannedActionData to be %s, got %s", i, expectedCall.PlannedActionData.GoString(), actualCall.PlannedActionData.GoString()) + if actualCall.ActionType != expectedCall.ActionType { + t.Fatalf("expected invoke action call %d ActionType to be %s, got %s", i, expectedCall.ActionType, actualCall.ActionType) + } + if !actualCall.PlannedActionData.RawEquals(expectedCall.PlannedActionData) { + t.Fatalf("expected invoke action call %d PlannedActionData to be %s, got %s", i, expectedCall.PlannedActionData.GoString(), actualCall.PlannedActionData.GoString()) + } } } })