Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test-cases to highlight possible phone inputs. #614

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion pagerduty/resource_pagerduty_user_contact_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,46 @@ func TestAccPagerDutyUserContactMethodPhone_Basic(t *testing.T) {
testAccCheckPagerDutyUserContactMethodExists("pagerduty_user_contact_method.foo"),
),
},
{
Config: testAccCheckPagerDutyUserContactMethodPhoneConfig(usernameUpdated, emailUpdated, "4153013250"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserContactMethodExists("pagerduty_user_contact_method.foo"),
),
},
},
})
}

// https://github.com/pagerduty/terraform-provider-pagerduty/blob/master/pagerduty/resource_pagerduty_user_contact_method.go#L26
func TestAccPagerDutyUserContactMethodPhone_Validation(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: testAccCheckPagerDutyUserContactMethodPhoneConfig(username, email, "415 301 3250"),
ExpectError: regexp.MustCompile("phone numbers should only contain digits"),
},
{
Config: testAccCheckPagerDutyUserContactMethodPhoneConfig(username, email, "415-301-3250"),
ExpectError: regexp.MustCompile("phone numbers should only contain digits"),
},
{
// NOTE: This error message is not useful in indicating what the issue with the input actually is.
Config: testAccCheckPagerDutyUserContactMethodPhoneConfig(username, email, "41530132501"),
ExpectError: regexp.MustCompile("phone numbers should only contain digits"),
},
{
Config: testAccCheckPagerDutyUserContactMethodPhoneConfig(username, email, "04153013250"),
ExpectError: regexp.MustCompile("phone numbers starting with a 0 are not supported"),
},
{
Config: testAccCheckPagerDutyUserContactMethodPhoneConfig(usernameUpdated, emailUpdated, "8019351337"),
// https://github.com/PagerDuty/terraform-provider-pagerduty/issues/578
Config: testAccCheckPagerDutyUserContactMethodPhoneConfigRandom(username, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserContactMethodExists("pagerduty_user_contact_method.foo"),
),
Expand Down Expand Up @@ -258,6 +292,32 @@ resource "pagerduty_user_contact_method" "foo" {
`, username, email, phone)
}

func testAccCheckPagerDutyUserContactMethodPhoneConfigRandom(username, email) string {
return fmt.Sprintf(`
resource "random_integer" "foo" {
min = 1000000000
max = 9999999999
}

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"
country_code = "+1"
address = tostring(random_integer.result)
label = "%[1]v"
}
`, username, email)
}

func testAccCheckPagerDutyUserContactMethodSMSConfig(username, email string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
Expand Down