diff --git a/helper/resource/teststep_providers_test.go b/helper/resource/teststep_providers_test.go index d371e47a9..9d122615e 100644 --- a/helper/resource/teststep_providers_test.go +++ b/helper/resource/teststep_providers_test.go @@ -2382,52 +2382,72 @@ func TestTest_TestStep_ProviderFactories_ExpectWarningRefresh(t *testing.T) { t.Parallel() Test(t, TestCase{ - ProviderFactories: map[string]func() (*schema.Provider, error){ - "random": func() (*schema.Provider, error) { //nolint:unparam // required signature - return &schema.Provider{ - ResourcesMap: map[string]*schema.Resource{ - "random_password": { - CreateContext: func(ctx context.Context, d *schema.ResourceData, i interface{}) diag.Diagnostics { - d.SetId("id") - return nil - }, - DeleteContext: func(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { - return nil - }, - ReadContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) (diags diag.Diagnostics) { - // Only generate diag when ReadContext is called for the second - // time during terraform refresh. - if d.Get("id") == "new_id" { - return append(diags, diag.Diagnostic{ - Severity: diag.Warning, - Summary: "warning diagnostic - summary", - }) - } - - // Update id when ReadContext is called following resource creation - // during terraform apply. - d.SetId("new_id") - - return - }, - Schema: map[string]*schema.Schema{ - "id": { - Computed: true, - Type: schema.TypeString, + Steps: []TestStep{ + { + ProviderFactories: map[string]func() (*schema.Provider, error){ + "random": func() (*schema.Provider, error) { //nolint:unparam // required signature + return &schema.Provider{ + ResourcesMap: map[string]*schema.Resource{ + "random_password": { + CreateContext: func(ctx context.Context, d *schema.ResourceData, i interface{}) diag.Diagnostics { + d.SetId("id") + return nil + }, + DeleteContext: func(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + return nil + }, + ReadContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) (diags diag.Diagnostics) { + return nil + }, + Schema: map[string]*schema.Schema{ + "id": { + Computed: true, + Type: schema.TypeString, + }, + }, }, }, - }, + }, nil }, - }, nil - }, - }, - Steps: []TestStep{ - { + }, Config: `resource "random_password" "test" { }`, }, { - RefreshState: true, - ExpectWarning: regexp.MustCompile(`.*warning diagnostic - summary`), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "random": func() (*schema.Provider, error) { //nolint:unparam // required signature + return &schema.Provider{ + ResourcesMap: map[string]*schema.Resource{ + "random_password": { + CreateContext: func(ctx context.Context, d *schema.ResourceData, i interface{}) diag.Diagnostics { + d.SetId("id") + return nil + }, + DeleteContext: func(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + return nil + }, + ReadContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) (diags diag.Diagnostics) { + return append(diags, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "warning diagnostic - summary", + }) + }, + Schema: map[string]*schema.Schema{ + "id": { + Computed: true, + Type: schema.TypeString, + }, + }, + }, + }, + }, nil + }, + }, + RefreshState: true, + // ExpectNonEmptyPlan is set to true otherwise following error is generated: + // # random_password.test will be destroyed + // # (because random_password.test is not in configuration) + ExpectNonEmptyPlan: true, + ExpectWarning: regexp.MustCompile(`.*warning diagnostic - summary`), }, }, })