Skip to content

Commit

Permalink
add testacc to cover regression
Browse files Browse the repository at this point in the history
  • Loading branch information
imjaroiswebdev committed Oct 31, 2023
1 parent 4f025c1 commit 58d403b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pagerduty/resource_pagerduty_user_contact_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ func TestAccPagerDutyUserContactMethodSMS_Basic(t *testing.T) {
})
}

func TestAccPagerDutyUserContactMethodPhone_NoPermaDiffWhenOmittingCountryCode(t *testing.T) {
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
email := fmt.Sprintf("%[email protected]", username)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyUserContactMethodDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyUserContactMethodPhoneNoPermaDiffWhenOmittingCountryCodeConfig(username, email, "4153013250"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserContactMethodExists("pagerduty_user_contact_method.foo"),
),
},
{
Config: testAccCheckPagerDutyUserContactMethodPhoneNoPermaDiffWhenOmittingCountryCodeConfig(username, email, "4153013250"),
PlanOnly: true,
},
},
})
}

func testAccCheckPagerDutyUserContactMethodDestroy(s *terraform.State) error {
client, _ := testAccProvider.Meta().(*Config).Client()
for _, r := range s.RootModule().Resources {
Expand Down Expand Up @@ -299,3 +322,23 @@ resource "pagerduty_user_contact_method" "foo" {
}
`, username, email)
}

func testAccCheckPagerDutyUserContactMethodPhoneNoPermaDiffWhenOmittingCountryCodeConfig(username, email, phone string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
name = "%[1]v"
email = "%[2]v"
color = "red"
role = "user"
job_title = "bar"
description = "bar"
}
resource "pagerduty_user_contact_method" "foo" {
user_id = pagerduty_user.foo.id
type = "phone_contact_method"
address = "%[3]s"
label = "%[1]v"
}
`, username, email, phone)
}

0 comments on commit 58d403b

Please sign in to comment.