From 23929abd07db1f69fb0449696d0efaa9023e90f9 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Thu, 31 Aug 2023 18:13:05 +0100 Subject: [PATCH] Fix regression by allowing providers defined at `TestCase` level with providers defined within `TestStep.Config` (#177) * Removing checking whether TestStep.Config contains provider block to reinstate prior behaviour (#176) * Adding changelog (#176) --- .changes/unreleased/BUG FIXES-20230831-171932.yaml | 6 ++++++ helper/resource/teststep_validate.go | 1 - helper/resource/teststep_validate_test.go | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/BUG FIXES-20230831-171932.yaml diff --git a/.changes/unreleased/BUG FIXES-20230831-171932.yaml b/.changes/unreleased/BUG FIXES-20230831-171932.yaml new file mode 100644 index 000000000..e66879636 --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20230831-171932.yaml @@ -0,0 +1,6 @@ +kind: BUG FIXES +body: 'helper/resource: Fix regression by allowing providers to be defined both at + the `TestCase` level, and within `TestStep.Config`' +time: 2023-08-31T17:19:32.516184+01:00 +custom: + Issue: "177" diff --git a/helper/resource/teststep_validate.go b/helper/resource/teststep_validate.go index cd90ed5cc..d63db4dc8 100644 --- a/helper/resource/teststep_validate.go +++ b/helper/resource/teststep_validate.go @@ -64,7 +64,6 @@ func (s TestStep) hasProviders(ctx context.Context, stepIndex int, testName stri configRequest := teststep.PrepareConfigurationRequest{ Directory: s.ConfigDirectory, File: s.ConfigFile, - Raw: s.Config, TestStepConfigRequest: config.TestStepConfigRequest{ StepNumber: stepIndex + 1, TestName: testName, diff --git a/helper/resource/teststep_validate_test.go b/helper/resource/teststep_validate_test.go index d47200926..c5f19a60e 100644 --- a/helper/resource/teststep_validate_test.go +++ b/helper/resource/teststep_validate_test.go @@ -282,6 +282,19 @@ func TestTestStepValidate(t *testing.T) { }, expectedError: fmt.Errorf("TestStep ImportState must be specified with ImportStateId, ImportStateIdFunc, or ResourceName"), }, + // This test has been added to verify that providers can be defined + // both within the TestStep.Config and at the TestCase level. + // The regression was reported in + // https://github.com/hashicorp/terraform-plugin-testing/issues/176 + "config-providers-testcase-providers": { + testStep: TestStep{ + Config: "provider abc {", + }, + testStepConfig: "# not empty", + testStepValidateRequest: testStepValidateRequest{ + TestCaseHasProviders: true, + }, + }, "protov5providerfactories-testcase-providers": { testStep: TestStep{ ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){