From a8e70a355f13cc2efeabe0048486d3cd6ad48577 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 18 Aug 2025 15:06:02 +0200 Subject: [PATCH] allow selectively sending another response for actions in plan tests --- .../terraform/context_plan_actions_test.go | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/terraform/context_plan_actions_test.go b/internal/terraform/context_plan_actions_test.go index 0e47eceb8c..fe8e7c1374 100644 --- a/internal/terraform/context_plan_actions_test.go +++ b/internal/terraform/context_plan_actions_test.go @@ -22,13 +22,12 @@ import ( ) func TestContextPlan_actions(t *testing.T) { - for name, tc := range map[string]struct { - toBeImplemented bool - module map[string]string - buildState func(*states.SyncState) - planActionResponse *providers.PlanActionResponse - planOpts *PlanOpts + toBeImplemented bool + module map[string]string + buildState func(*states.SyncState) + planActionFn func(providers.PlanActionRequest) providers.PlanActionResponse + planOpts *PlanOpts expectPlanActionCalled bool @@ -683,10 +682,12 @@ resource "test_object" "a" { `, }, - planActionResponse: &providers.PlanActionResponse{ - Diagnostics: tfdiags.Diagnostics{ - tfdiags.Sourceless(tfdiags.Error, "Planning failed", "Test case simulates an error while planning"), - }, + planActionFn: func(_ providers.PlanActionRequest) providers.PlanActionResponse { + return providers.PlanActionResponse{ + Diagnostics: tfdiags.Diagnostics{ + tfdiags.Sourceless(tfdiags.Error, "Planning failed", "Test case simulates an error while planning"), + }, + } }, expectPlanActionCalled: true, @@ -1421,8 +1422,8 @@ resource "test_object" "a" { }, } - if tc.planActionResponse != nil { - p.PlanActionResponse = *tc.planActionResponse + if tc.planActionFn != nil { + p.PlanActionFn = tc.planActionFn } ctx := testContext2(t, &ContextOpts{