From 58d403b2ef3d3c37b5884fdab9f6ff4c35d19a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Tue, 31 Oct 2023 16:27:12 -0300 Subject: [PATCH] add testacc to cover regression --- ...urce_pagerduty_user_contact_method_test.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pagerduty/resource_pagerduty_user_contact_method_test.go b/pagerduty/resource_pagerduty_user_contact_method_test.go index be2624539..3e3574779 100644 --- a/pagerduty/resource_pagerduty_user_contact_method_test.go +++ b/pagerduty/resource_pagerduty_user_contact_method_test.go @@ -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("%s@foo.test", 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 { @@ -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) +}