Skip to content

Commit

Permalink
Add test to verify that warnings are generated during test step execu…
Browse files Browse the repository at this point in the history
…tion (#16)
  • Loading branch information
bendbennett committed Jan 3, 2023
1 parent e16d5b3 commit e8f0f74
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions helper/resource/teststep_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resource
import (
"context"
"fmt"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -2129,6 +2130,48 @@ func TestTest_TestStep_ProviderFactories_Import_External_With_Data_Source(t *tes
})
}

func TestTest_TestStep_ProviderFactories_ExpectWarning(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{}) (diags diag.Diagnostics) {
d.SetId("id")
return append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "warning diagnostic - summary",
})
},
DeleteContext: func(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
return nil
},
ReadContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
return nil
},
Schema: map[string]*schema.Schema{
"id": {
Computed: true,
Type: schema.TypeString,
},
},
},
},
}, nil
},
},
Steps: []TestStep{
{
Config: `resource "random_password" "test" { }`,
ExpectWarning: regexp.MustCompile(`.*warning diagnostic - summary`),
},
},
})
}

func setTimeForTest(t time.Time) func() {
return func() {
getTimeForTest = func() time.Time {
Expand Down

0 comments on commit e8f0f74

Please sign in to comment.