From 0736dde0f7ccac4f5c6fce1b2847080cf8e3c4fb Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 11 May 2017 16:14:30 +0200 Subject: [PATCH] provider/pagerduty: Randomize names in acceptance tests (#14364) * Randomize names for pagerduty_user * Randomize names for pagerduty_team * Randomize names for pagerduty_service * Randomize names for pagerduty_service_integration * Randomize names for pagerduty_schedule * Randomize names for pagerduty_escalation_policy * Randomize names for pagerduty_addon * Randomize names for data_pagerduty_user * Randomize names for data_pagerduty_schedule * Randomize names for data_pagerduty_escalation_policy * Run in parallel if $PAGERDUTY_PARALLEL is passed --- ...source_pagerduty_escalation_policy_test.go | 19 +-- .../data_source_pagerduty_schedule_test.go | 19 +-- .../data_source_pagerduty_user_test.go | 16 +-- ...import_pagerduty_escalation_policy_test.go | 14 ++- .../import_pagerduty_schedule_test.go | 14 ++- ...port_pagerduty_service_integration_test.go | 16 ++- .../import_pagerduty_service_test.go | 28 +++-- .../pagerduty/import_pagerduty_team_test.go | 12 +- .../pagerduty/import_pagerduty_user_test.go | 13 +- builtin/providers/pagerduty/provider_test.go | 4 + .../resource_pagerduty_addon_test.go | 32 +++-- ...source_pagerduty_escalation_policy_test.go | 89 ++++++++------ .../resource_pagerduty_schedule_test.go | 105 +++++++++------- ...urce_pagerduty_service_integration_test.go | 103 +++++++++------- .../resource_pagerduty_service_test.go | 113 +++++++++++------- .../pagerduty/resource_pagerduty_team_test.go | 30 +++-- .../pagerduty/resource_pagerduty_user_test.go | 110 ++++++++++------- 17 files changed, 453 insertions(+), 284 deletions(-) diff --git a/builtin/providers/pagerduty/data_source_pagerduty_escalation_policy_test.go b/builtin/providers/pagerduty/data_source_pagerduty_escalation_policy_test.go index 929c72303..cd93e5c71 100644 --- a/builtin/providers/pagerduty/data_source_pagerduty_escalation_policy_test.go +++ b/builtin/providers/pagerduty/data_source_pagerduty_escalation_policy_test.go @@ -10,13 +10,16 @@ import ( ) func TestAccDataSourcePagerDutyEscalationPolicy_Basic(t *testing.T) { - rName := acctest.RandString(5) + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccDataSourcePagerDutyEscalationPolicyConfig(rName), + { + Config: testAccDataSourcePagerDutyEscalationPolicyConfig(username, email, escalationPolicy), Check: resource.ComposeTestCheckFunc( testAccDataSourcePagerDutyEscalationPolicy("pagerduty_escalation_policy.test", "data.pagerduty_escalation_policy.by_name"), ), @@ -50,15 +53,15 @@ func testAccDataSourcePagerDutyEscalationPolicy(src, n string) resource.TestChec } } -func testAccDataSourcePagerDutyEscalationPolicyConfig(rName string) string { +func testAccDataSourcePagerDutyEscalationPolicyConfig(username, email, escalationPolicy string) string { return fmt.Sprintf(` resource "pagerduty_user" "test" { - name = "TF User %[1]s" - email = "tf.%[1]s@example.com" + name = "%s" + email = "%s" } resource "pagerduty_escalation_policy" "test" { - name = "TF Escalation Policy %[1]v" + name = "%s" num_loops = 2 rule { @@ -74,5 +77,5 @@ resource "pagerduty_escalation_policy" "test" { data "pagerduty_escalation_policy" "by_name" { name = "${pagerduty_escalation_policy.test.name}" } -`, rName) +`, username, email, escalationPolicy) } diff --git a/builtin/providers/pagerduty/data_source_pagerduty_schedule_test.go b/builtin/providers/pagerduty/data_source_pagerduty_schedule_test.go index a3a7075f5..93338595a 100644 --- a/builtin/providers/pagerduty/data_source_pagerduty_schedule_test.go +++ b/builtin/providers/pagerduty/data_source_pagerduty_schedule_test.go @@ -10,13 +10,16 @@ import ( ) func TestAccDataSourcePagerDutySchedule_Basic(t *testing.T) { - rName := acctest.RandString(5) + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + schedule := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccDataSourcePagerDutyScheduleConfig(rName), + { + Config: testAccDataSourcePagerDutyScheduleConfig(username, email, schedule), Check: resource.ComposeTestCheckFunc( testAccDataSourcePagerDutySchedule("pagerduty_schedule.test", "data.pagerduty_schedule.by_name"), ), @@ -50,15 +53,15 @@ func testAccDataSourcePagerDutySchedule(src, n string) resource.TestCheckFunc { } } -func testAccDataSourcePagerDutyScheduleConfig(rName string) string { +func testAccDataSourcePagerDutyScheduleConfig(username, email, schedule string) string { return fmt.Sprintf(` resource "pagerduty_user" "test" { - name = "TF User %[1]s" - email = "tf.%[1]s@example.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "test" { - name = "TF Schedule %[1]s" + name = "%s" time_zone = "America/New_York" @@ -81,5 +84,5 @@ resource "pagerduty_schedule" "test" { data "pagerduty_schedule" "by_name" { name = "${pagerduty_schedule.test.name}" } -`, rName) +`, username, email, schedule) } diff --git a/builtin/providers/pagerduty/data_source_pagerduty_user_test.go b/builtin/providers/pagerduty/data_source_pagerduty_user_test.go index e2ab336f0..2c09d9231 100644 --- a/builtin/providers/pagerduty/data_source_pagerduty_user_test.go +++ b/builtin/providers/pagerduty/data_source_pagerduty_user_test.go @@ -10,13 +10,15 @@ import ( ) func TestAccDataSourcePagerDutyUser_Basic(t *testing.T) { - rName := acctest.RandString(5) + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccDataSourcePagerDutyUserConfig(rName), + { + Config: testAccDataSourcePagerDutyUserConfig(username, email), Check: resource.ComposeTestCheckFunc( testAccDataSourcePagerDutyUser("pagerduty_user.test", "data.pagerduty_user.by_email"), ), @@ -50,15 +52,15 @@ func testAccDataSourcePagerDutyUser(src, n string) resource.TestCheckFunc { } } -func testAccDataSourcePagerDutyUserConfig(rName string) string { +func testAccDataSourcePagerDutyUserConfig(username, email string) string { return fmt.Sprintf(` resource "pagerduty_user" "test" { - name = "TF User %[1]s" - email = "tf.%[1]s@example.com" + name = "%s" + email = "%s" } data "pagerduty_user" "by_email" { email = "${pagerduty_user.test.email}" } -`, rName) +`, username, email) } diff --git a/builtin/providers/pagerduty/import_pagerduty_escalation_policy_test.go b/builtin/providers/pagerduty/import_pagerduty_escalation_policy_test.go index d71e50a19..5feb94fc9 100644 --- a/builtin/providers/pagerduty/import_pagerduty_escalation_policy_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_escalation_policy_test.go @@ -1,25 +1,29 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutyEscalationPolicy_import(t *testing.T) { - resourceName := "pagerduty_escalation_policy.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyEscalationPolicyConfig, + { + Config: testAccCheckPagerDutyEscalationPolicyConfig(username, email, escalationPolicy), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_escalation_policy.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/import_pagerduty_schedule_test.go b/builtin/providers/pagerduty/import_pagerduty_schedule_test.go index 41e06f7d3..3cc0db866 100644 --- a/builtin/providers/pagerduty/import_pagerduty_schedule_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_schedule_test.go @@ -1,25 +1,29 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutySchedule_import(t *testing.T) { - resourceName := "pagerduty_schedule.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + schedule := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyUserDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfig, + { + Config: testAccCheckPagerDutyScheduleConfig(username, email, schedule), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_schedule.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/import_pagerduty_service_integration_test.go b/builtin/providers/pagerduty/import_pagerduty_service_integration_test.go index 38c3a060b..9b0ccfdcf 100644 --- a/builtin/providers/pagerduty/import_pagerduty_service_integration_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_service_integration_test.go @@ -1,25 +1,31 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutyServiceIntegration_import(t *testing.T) { - resourceName := "pagerduty_service_integration.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceIntegration := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceIntegrationConfig, + { + Config: testAccCheckPagerDutyServiceIntegrationConfig(username, email, escalationPolicy, service, serviceIntegration), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_service_integration.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/import_pagerduty_service_test.go b/builtin/providers/pagerduty/import_pagerduty_service_test.go index 28259c74b..516411a7f 100644 --- a/builtin/providers/pagerduty/import_pagerduty_service_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_service_test.go @@ -1,25 +1,30 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutyService_import(t *testing.T) { - resourceName := "pagerduty_service.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceConfig, + { + Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_service.foo", ImportState: true, ImportStateVerify: true, }, @@ -28,19 +33,22 @@ func TestAccPagerDutyService_import(t *testing.T) { } func TestAccPagerDutyServiceWithIncidentUrgency_import(t *testing.T) { - resourceName := "pagerduty_service.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig, + { + Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_service.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/import_pagerduty_team_test.go b/builtin/providers/pagerduty/import_pagerduty_team_test.go index 5017167a3..51a22f91c 100644 --- a/builtin/providers/pagerduty/import_pagerduty_team_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_team_test.go @@ -1,25 +1,27 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutyTeam_import(t *testing.T) { - resourceName := "pagerduty_team.foo" + team := fmt.Sprintf("tf-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyTeamDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyTeamConfig, + { + Config: testAccCheckPagerDutyTeamConfig(team), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_team.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/import_pagerduty_user_test.go b/builtin/providers/pagerduty/import_pagerduty_user_test.go index 82d7cc99b..6f130401a 100644 --- a/builtin/providers/pagerduty/import_pagerduty_user_test.go +++ b/builtin/providers/pagerduty/import_pagerduty_user_test.go @@ -1,25 +1,28 @@ package pagerduty import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccPagerDutyUser_import(t *testing.T) { - resourceName := "pagerduty_user.foo" + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyUserDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyUserConfig, + { + Config: testAccCheckPagerDutyUserConfig(username, email), }, - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "pagerduty_user.foo", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/pagerduty/provider_test.go b/builtin/providers/pagerduty/provider_test.go index b72ccae69..906c4e5c8 100644 --- a/builtin/providers/pagerduty/provider_test.go +++ b/builtin/providers/pagerduty/provider_test.go @@ -29,6 +29,10 @@ func TestProviderImpl(t *testing.T) { } func testAccPreCheck(t *testing.T) { + if v := os.Getenv("PAGERDUTY_PARALLEL"); v != "" { + t.Parallel() + } + if v := os.Getenv("PAGERDUTY_TOKEN"); v == "" { t.Fatal("PAGERDUTY_TOKEN must be set for acceptance tests") } diff --git a/builtin/providers/pagerduty/resource_pagerduty_addon_test.go b/builtin/providers/pagerduty/resource_pagerduty_addon_test.go index c6cee5dcb..639153b1e 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_addon_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_addon_test.go @@ -5,32 +5,36 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyAddon_Basic(t *testing.T) { + addon := fmt.Sprintf("tf-%s", acctest.RandString(5)) + addonUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyAddonDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyAddonConfig, + { + Config: testAccCheckPagerDutyAddonConfig(addon), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"), resource.TestCheckResourceAttr( - "pagerduty_addon.foo", "name", "Foo status page"), + "pagerduty_addon.foo", "name", addon), resource.TestCheckResourceAttr( "pagerduty_addon.foo", "src", "https://intranet.foo.com/status"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyAddonConfigUpdated, + { + Config: testAccCheckPagerDutyAddonConfigUpdated(addonUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"), resource.TestCheckResourceAttr( - "pagerduty_addon.foo", "name", "Bar status page"), + "pagerduty_addon.foo", "name", addonUpdated), resource.TestCheckResourceAttr( "pagerduty_addon.foo", "src", "https://intranet.bar.com/status"), ), @@ -80,16 +84,20 @@ func testAccCheckPagerDutyAddonExists(n string) resource.TestCheckFunc { } } -const testAccCheckPagerDutyAddonConfig = ` +func testAccCheckPagerDutyAddonConfig(addon string) string { + return fmt.Sprintf(` resource "pagerduty_addon" "foo" { - name = "Foo status page" + name = "%s" src = "https://intranet.foo.com/status" } -` +`, addon) +} -const testAccCheckPagerDutyAddonConfigUpdated = ` +func testAccCheckPagerDutyAddonConfigUpdated(addon string) string { + return fmt.Sprintf(` resource "pagerduty_addon" "foo" { - name = "Bar status page" + name = "%s" src = "https://intranet.bar.com/status" } -` +`, addon) +} diff --git a/builtin/providers/pagerduty/resource_pagerduty_escalation_policy_test.go b/builtin/providers/pagerduty/resource_pagerduty_escalation_policy_test.go index 2ca484105..c70d95809 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_escalation_policy_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_escalation_policy_test.go @@ -5,22 +5,28 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + escalationPolicyUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyEscalationPolicyConfig, + { + Config: testAccCheckPagerDutyEscalationPolicyConfig(username, email, escalationPolicy), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), resource.TestCheckResourceAttr( - "pagerduty_escalation_policy.foo", "name", "foo"), + "pagerduty_escalation_policy.foo", "name", escalationPolicy), resource.TestCheckResourceAttr( "pagerduty_escalation_policy.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -31,12 +37,13 @@ func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) { "pagerduty_escalation_policy.foo", "rule.0.escalation_delay_in_minutes", "10"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyEscalationPolicyConfigUpdated, + + { + Config: testAccCheckPagerDutyEscalationPolicyConfigUpdated(username, email, escalationPolicyUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), resource.TestCheckResourceAttr( - "pagerduty_escalation_policy.foo", "name", "bar"), + "pagerduty_escalation_policy.foo", "name", escalationPolicyUpdated), resource.TestCheckResourceAttr( "pagerduty_escalation_policy.foo", "description", "bar"), resource.TestCheckResourceAttr( @@ -54,17 +61,23 @@ func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) { } func TestAccPagerDutyEscalationPolicyWithTeams_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + team := fmt.Sprintf("tf-%s", acctest.RandString(5)) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + escalationPolicyUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfig, + { + Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfig(username, email, team, escalationPolicy), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), resource.TestCheckResourceAttr( - "pagerduty_escalation_policy.foo", "name", "foo"), + "pagerduty_escalation_policy.foo", "name", escalationPolicy), resource.TestCheckResourceAttr( "pagerduty_escalation_policy.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -77,12 +90,12 @@ func TestAccPagerDutyEscalationPolicyWithTeams_Basic(t *testing.T) { "pagerduty_escalation_policy.foo", "teams.#", "1"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated, + { + Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated(username, email, team, escalationPolicyUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), resource.TestCheckResourceAttr( - "pagerduty_escalation_policy.foo", "name", "bar"), + "pagerduty_escalation_policy.foo", "name", escalationPolicyUpdated), resource.TestCheckResourceAttr( "pagerduty_escalation_policy.foo", "description", "bar"), resource.TestCheckResourceAttr( @@ -143,10 +156,11 @@ func testAccCheckPagerDutyEscalationPolicyExists(n string) resource.TestCheckFun } } -const testAccCheckPagerDutyEscalationPolicyConfig = ` +func testAccCheckPagerDutyEscalationPolicyConfig(name, email, escalationPolicy string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -154,7 +168,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "foo" + name = "%s" description = "foo" num_loops = 1 @@ -167,12 +181,14 @@ resource "pagerduty_escalation_policy" "foo" { } } } -` +`, name, email, escalationPolicy) +} -const testAccCheckPagerDutyEscalationPolicyConfigUpdated = ` +func testAccCheckPagerDutyEscalationPolicyConfigUpdated(name, email, escalationPolicy string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -180,7 +196,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -202,12 +218,14 @@ resource "pagerduty_escalation_policy" "foo" { } } } -` +`, name, email, escalationPolicy) +} -const testAccCheckPagerDutyEscalationPolicyWithTeamsConfig = ` +func testAccCheckPagerDutyEscalationPolicyWithTeamsConfig(name, email, team, escalationPolicy string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -215,12 +233,12 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_team" "foo" { - name = "foo" + name = "%s" description = "foo" } resource "pagerduty_escalation_policy" "foo" { - name = "foo" + name = "%s" description = "foo" num_loops = 1 teams = ["${pagerduty_team.foo.id}"] @@ -234,12 +252,14 @@ resource "pagerduty_escalation_policy" "foo" { } } } -` +`, name, email, team, escalationPolicy) +} -const testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated = ` +func testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated(name, email, team, escalationPolicy string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -247,12 +267,12 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_team" "foo" { - name = "foo" + name = "%s" description = "foo" } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -274,4 +294,5 @@ resource "pagerduty_escalation_policy" "foo" { } } } -` +`, name, email, team, escalationPolicy) +} diff --git a/builtin/providers/pagerduty/resource_pagerduty_schedule_test.go b/builtin/providers/pagerduty/resource_pagerduty_schedule_test.go index a4989efcd..09eb9f604 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_schedule_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_schedule_test.go @@ -5,22 +5,28 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutySchedule_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + schedule := fmt.Sprintf("tf-%s", acctest.RandString(5)) + scheduleUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfig, + { + Config: testAccCheckPagerDutyScheduleConfig(username, email, schedule), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), resource.TestCheckResourceAttr( - "pagerduty_schedule.foo", "name", "foo"), + "pagerduty_schedule.foo", "name", schedule), resource.TestCheckResourceAttr( "pagerduty_schedule.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -31,12 +37,12 @@ func TestAccPagerDutySchedule_Basic(t *testing.T) { "pagerduty_schedule.foo", "layer.0.name", "foo"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfigUpdated, + { + Config: testAccCheckPagerDutyScheduleConfigUpdated(username, email, scheduleUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), resource.TestCheckResourceAttr( - "pagerduty_schedule.foo", "name", "bar"), + "pagerduty_schedule.foo", "name", scheduleUpdated), resource.TestCheckResourceAttr( "pagerduty_schedule.foo", "description", "Managed by Terraform"), resource.TestCheckResourceAttr( @@ -52,17 +58,22 @@ func TestAccPagerDutySchedule_Basic(t *testing.T) { } func TestAccPagerDutySchedule_BasicWeek(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + schedule := fmt.Sprintf("tf-%s", acctest.RandString(5)) + scheduleUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfigWeek, + { + Config: testAccCheckPagerDutyScheduleConfigWeek(username, email, schedule), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), resource.TestCheckResourceAttr( - "pagerduty_schedule.foo", "name", "foo"), + "pagerduty_schedule.foo", "name", schedule), resource.TestCheckResourceAttr( "pagerduty_schedule.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -75,12 +86,12 @@ func TestAccPagerDutySchedule_BasicWeek(t *testing.T) { "pagerduty_schedule.foo", "layer.0.restriction.0.start_day_of_week", "1"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfigWeekUpdated, + { + Config: testAccCheckPagerDutyScheduleConfigWeekUpdated(username, email, scheduleUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), resource.TestCheckResourceAttr( - "pagerduty_schedule.foo", "name", "bar"), + "pagerduty_schedule.foo", "name", scheduleUpdated), resource.TestCheckResourceAttr( "pagerduty_schedule.foo", "description", "Managed by Terraform"), resource.TestCheckResourceAttr( @@ -98,17 +109,21 @@ func TestAccPagerDutySchedule_BasicWeek(t *testing.T) { } func TestAccPagerDutySchedule_Multi(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + schedule := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyScheduleConfigMulti, + { + Config: testAccCheckPagerDutyScheduleConfigMulti(username, email, schedule), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), resource.TestCheckResourceAttr( - "pagerduty_schedule.foo", "name", "foo"), + "pagerduty_schedule.foo", "name", schedule), resource.TestCheckResourceAttr( "pagerduty_schedule.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -215,14 +230,15 @@ func testAccCheckPagerDutyScheduleExists(n string) resource.TestCheckFunc { } } -const testAccCheckPagerDutyScheduleConfig = ` +func testAccCheckPagerDutyScheduleConfig(username, email, schedule string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "foo" { - name = "foo" + name = "%s" time_zone = "Europe/Berlin" description = "foo" @@ -241,16 +257,18 @@ resource "pagerduty_schedule" "foo" { } } } -` +`, username, email, schedule) +} -const testAccCheckPagerDutyScheduleConfigUpdated = ` +func testAccCheckPagerDutyScheduleConfigUpdated(username, email, schedule string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "foo" { - name = "bar" + name = "%s" time_zone = "America/New_York" @@ -268,16 +286,18 @@ resource "pagerduty_schedule" "foo" { } } } -` +`, username, email, schedule) +} -const testAccCheckPagerDutyScheduleConfigWeek = ` +func testAccCheckPagerDutyScheduleConfigWeek(username, email, schedule string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "foo" { - name = "foo" + name = "%s" time_zone = "Europe/Berlin" description = "foo" @@ -297,16 +317,18 @@ resource "pagerduty_schedule" "foo" { } } } -` +`, username, email, schedule) +} -const testAccCheckPagerDutyScheduleConfigWeekUpdated = ` +func testAccCheckPagerDutyScheduleConfigWeekUpdated(username, email, schedule string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "foo" { - name = "bar" + name = "%s" time_zone = "America/New_York" @@ -325,16 +347,18 @@ resource "pagerduty_schedule" "foo" { } } } -` +`, username, email, schedule) +} -const testAccCheckPagerDutyScheduleConfigMulti = ` +func testAccCheckPagerDutyScheduleConfigMulti(username, email, schedule string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_schedule" "foo" { - name = "foo" + name = "%s" time_zone = "America/New_York" description = "foo" @@ -383,4 +407,5 @@ resource "pagerduty_schedule" "foo" { } } } -` +`, username, email, schedule) +} diff --git a/builtin/providers/pagerduty/resource_pagerduty_service_integration_test.go b/builtin/providers/pagerduty/resource_pagerduty_service_integration_test.go index eb58dd480..0aa451fc4 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_service_integration_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_service_integration_test.go @@ -5,34 +5,42 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyServiceIntegration_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceIntegration := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceIntegrationUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceIntegrationConfig, + { + Config: testAccCheckPagerDutyServiceIntegrationConfig(username, email, escalationPolicy, service, serviceIntegration), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), resource.TestCheckResourceAttr( - "pagerduty_service_integration.foo", "name", "foo"), + "pagerduty_service_integration.foo", "name", serviceIntegration), resource.TestCheckResourceAttr( "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), resource.TestCheckResourceAttr( "pagerduty_service_integration.foo", "vendor", "PAM4FGS"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyServiceIntegrationConfigUpdated, + { + Config: testAccCheckPagerDutyServiceIntegrationConfigUpdated(username, email, escalationPolicy, service, serviceIntegrationUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), resource.TestCheckResourceAttr( - "pagerduty_service_integration.foo", "name", "bar"), + "pagerduty_service_integration.foo", "name", serviceIntegrationUpdated), resource.TestCheckResourceAttr( "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), resource.TestCheckResourceAttr( @@ -44,27 +52,34 @@ func TestAccPagerDutyServiceIntegration_Basic(t *testing.T) { } func TestAccPagerDutyServiceIntegrationGeneric_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceIntegration := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceIntegrationUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceIntegrationGenericConfig, + { + Config: testAccCheckPagerDutyServiceIntegrationGenericConfig(username, email, escalationPolicy, service, serviceIntegration), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), resource.TestCheckResourceAttr( - "pagerduty_service_integration.foo", "name", "foo"), + "pagerduty_service_integration.foo", "name", serviceIntegration), resource.TestCheckResourceAttr( "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated, + { + Config: testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated(username, email, escalationPolicy, service, serviceIntegrationUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), resource.TestCheckResourceAttr( - "pagerduty_service_integration.foo", "name", "bar"), + "pagerduty_service_integration.foo", "name", serviceIntegrationUpdated), resource.TestCheckResourceAttr( "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), ), @@ -120,14 +135,15 @@ func testAccCheckPagerDutyServiceIntegrationExists(n string) resource.TestCheckF } } -const testAccCheckPagerDutyServiceIntegrationConfig = ` +func testAccCheckPagerDutyServiceIntegrationConfig(username, email, escalationPolicy, service, serviceIntegration string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_escalation_policy" "foo" { - name = "foo" + name = "%s" description = "foo" num_loops = 1 @@ -142,7 +158,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "foo" + name = "%s" description = "foo" auto_resolve_timeout = 1800 acknowledgement_timeout = 1800 @@ -159,16 +175,18 @@ data "pagerduty_vendor" "datadog" { } resource "pagerduty_service_integration" "foo" { - name = "foo" + name = "%s" service = "${pagerduty_service.foo.id}" vendor = "${data.pagerduty_vendor.datadog.id}" } -` +`, username, email, escalationPolicy, service, serviceIntegration) +} -const testAccCheckPagerDutyServiceIntegrationConfigUpdated = ` +func testAccCheckPagerDutyServiceIntegrationConfigUpdated(username, email, escalationPolicy, service, serviceIntegration string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -176,7 +194,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -191,7 +209,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "bar" + name = "%s" description = "bar" auto_resolve_timeout = 3600 acknowledgement_timeout = 3600 @@ -208,20 +226,22 @@ data "pagerduty_vendor" "datadog" { } resource "pagerduty_service_integration" "foo" { - name = "bar" + name = "%s" service = "${pagerduty_service.foo.id}" vendor = "${data.pagerduty_vendor.datadog.id}" } -` +`, username, email, escalationPolicy, service, serviceIntegration) +} -const testAccCheckPagerDutyServiceIntegrationGenericConfig = ` +func testAccCheckPagerDutyServiceIntegrationGenericConfig(username, email, escalationPolicy, service, serviceIntegration string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" } resource "pagerduty_escalation_policy" "foo" { - name = "foo" + name = "%s" description = "foo" num_loops = 1 @@ -236,7 +256,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "foo" + name = "%s" description = "foo" auto_resolve_timeout = 1800 acknowledgement_timeout = 1800 @@ -249,16 +269,18 @@ resource "pagerduty_service" "foo" { } resource "pagerduty_service_integration" "foo" { - name = "foo" + name = "%s" service = "${pagerduty_service.foo.id}" type = "generic_events_api_inbound_integration" } -` +`, username, email, escalationPolicy, service, serviceIntegration) +} -const testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated = ` +func testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated(username, email, escalationPolicy, service, serviceIntegration string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -266,7 +288,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -281,7 +303,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "bar" + name = "%s" description = "bar" auto_resolve_timeout = 3600 acknowledgement_timeout = 3600 @@ -294,8 +316,9 @@ resource "pagerduty_service" "foo" { } resource "pagerduty_service_integration" "foo" { - name = "bar" + name = "%s" service = "${pagerduty_service.foo.id}" type = "generic_events_api_inbound_integration" } -` +`, username, email, escalationPolicy, service, serviceIntegration) +} diff --git a/builtin/providers/pagerduty/resource_pagerduty_service_test.go b/builtin/providers/pagerduty/resource_pagerduty_service_test.go index afd2c59c1..b169b1b0f 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_service_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_service_test.go @@ -5,22 +5,29 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyService_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceConfig, + { + Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "foo"), + "pagerduty_service.foo", "name", service), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -35,12 +42,12 @@ func TestAccPagerDutyService_Basic(t *testing.T) { "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyServiceConfigUpdated, + { + Config: testAccCheckPagerDutyServiceConfigUpdated(username, email, escalationPolicy, serviceUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "bar"), + "pagerduty_service.foo", "name", serviceUpdated), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "bar"), resource.TestCheckResourceAttr( @@ -60,17 +67,23 @@ func TestAccPagerDutyService_Basic(t *testing.T) { } func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig, + { + Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "foo"), + "pagerduty_service.foo", "name", service), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -127,12 +140,12 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) { "pagerduty_service.foo", "support_hours.0.type", "fixed_time_per_day"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated, + { + Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, serviceUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "bar"), + "pagerduty_service.foo", "name", serviceUpdated), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "bar bar bar"), resource.TestCheckResourceAttr( @@ -194,17 +207,23 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) { } func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + serviceUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyServiceConfig, + { + Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "foo"), + "pagerduty_service.foo", "name", service), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "foo"), resource.TestCheckResourceAttr( @@ -219,12 +238,12 @@ func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(t *testing.T) "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated, + { + Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, serviceUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", "bar"), + "pagerduty_service.foo", "name", serviceUpdated), resource.TestCheckResourceAttr( "pagerduty_service.foo", "description", "bar bar bar"), resource.TestCheckResourceAttr( @@ -328,10 +347,11 @@ func testAccCheckPagerDutyServiceExists(n string) resource.TestCheckFunc { } } -const testAccCheckPagerDutyServiceConfig = ` +func testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@example.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -339,7 +359,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 rule { @@ -352,7 +372,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "foo" + name = "%s" description = "foo" auto_resolve_timeout = 1800 acknowledgement_timeout = 1800 @@ -362,12 +382,14 @@ resource "pagerduty_service" "foo" { urgency = "high" } } -` +`, username, email, escalationPolicy, service) +} -const testAccCheckPagerDutyServiceConfigUpdated = ` +func testAccCheckPagerDutyServiceConfigUpdated(username, email, escalationPolicy, service string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@example.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -375,7 +397,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -389,7 +411,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "bar" + name = "%s" description = "bar" auto_resolve_timeout = 3600 acknowledgement_timeout = 3600 @@ -400,12 +422,14 @@ resource "pagerduty_service" "foo" { urgency = "high" } } -` +`, username, email, escalationPolicy, service) +} -const testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig = ` +func testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@example.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -413,7 +437,7 @@ resource "pagerduty_user" "foo" { } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -427,7 +451,7 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "foo" + name = "%s" description = "foo" auto_resolve_timeout = 1800 acknowledgement_timeout = 1800 @@ -463,12 +487,14 @@ resource "pagerduty_service" "foo" { } } } -` +`, username, email, escalationPolicy, service) +} -const testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated = ` +func testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, service string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@example.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" @@ -476,7 +502,7 @@ const testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated = ` } resource "pagerduty_escalation_policy" "foo" { - name = "bar" + name = "%s" description = "bar" num_loops = 2 @@ -490,12 +516,12 @@ resource "pagerduty_escalation_policy" "foo" { } resource "pagerduty_service" "foo" { - name = "bar" + name = "%s" description = "bar bar bar" auto_resolve_timeout = 3600 acknowledgement_timeout = 3600 escalation_policy = "${pagerduty_escalation_policy.foo.id}" - + incident_urgency_rule { type = "use_support_hours" during_support_hours { @@ -525,4 +551,5 @@ resource "pagerduty_service" "foo" { } } } -` +`, username, email, escalationPolicy, service) +} diff --git a/builtin/providers/pagerduty/resource_pagerduty_team_test.go b/builtin/providers/pagerduty/resource_pagerduty_team_test.go index 369440ee9..1695a158b 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_team_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_team_test.go @@ -5,32 +5,36 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyTeam_Basic(t *testing.T) { + team := fmt.Sprintf("tf-%s", acctest.RandString(5)) + teamUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyTeamDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyTeamConfig, + { + Config: testAccCheckPagerDutyTeamConfig(team), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyTeamExists("pagerduty_team.foo"), resource.TestCheckResourceAttr( - "pagerduty_team.foo", "name", "foo"), + "pagerduty_team.foo", "name", team), resource.TestCheckResourceAttr( "pagerduty_team.foo", "description", "foo"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyTeamConfigUpdated, + { + Config: testAccCheckPagerDutyTeamConfigUpdated(teamUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyTeamExists("pagerduty_team.foo"), resource.TestCheckResourceAttr( - "pagerduty_team.foo", "name", "bar"), + "pagerduty_team.foo", "name", teamUpdated), resource.TestCheckResourceAttr( "pagerduty_team.foo", "description", "bar"), ), @@ -68,16 +72,18 @@ func testAccCheckPagerDutyTeamExists(n string) resource.TestCheckFunc { } } -const testAccCheckPagerDutyTeamConfig = ` +func testAccCheckPagerDutyTeamConfig(team string) string { + return fmt.Sprintf(` resource "pagerduty_team" "foo" { - name = "foo" + name = "%s" description = "foo" +}`, team) } -` -const testAccCheckPagerDutyTeamConfigUpdated = ` +func testAccCheckPagerDutyTeamConfigUpdated(team string) string { + return fmt.Sprintf(` resource "pagerduty_team" "foo" { - name = "bar" + name = "%s" description = "bar" +}`, team) } -` diff --git a/builtin/providers/pagerduty/resource_pagerduty_user_test.go b/builtin/providers/pagerduty/resource_pagerduty_user_test.go index 5df51f3c2..bdb1d22e4 100644 --- a/builtin/providers/pagerduty/resource_pagerduty_user_test.go +++ b/builtin/providers/pagerduty/resource_pagerduty_user_test.go @@ -5,24 +5,30 @@ import ( "testing" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccPagerDutyUser_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + usernameUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + emailUpdated := fmt.Sprintf("%s@foo.com", usernameUpdated) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyUserDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyUserConfig, + { + Config: testAccCheckPagerDutyUserConfig(username, email), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyUserExists("pagerduty_user.foo"), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "name", "foo"), + "pagerduty_user.foo", "name", username), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "email", "foo@bar.com"), + "pagerduty_user.foo", "email", email), resource.TestCheckResourceAttr( "pagerduty_user.foo", "color", "green"), resource.TestCheckResourceAttr( @@ -33,14 +39,14 @@ func TestAccPagerDutyUser_Basic(t *testing.T) { "pagerduty_user.foo", "description", "foo"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyUserConfigUpdated, + { + Config: testAccCheckPagerDutyUserConfigUpdated(usernameUpdated, emailUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyUserExists("pagerduty_user.foo"), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "name", "bar"), + "pagerduty_user.foo", "name", usernameUpdated), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "email", "bar@foo.com"), + "pagerduty_user.foo", "email", emailUpdated), resource.TestCheckResourceAttr( "pagerduty_user.foo", "color", "red"), resource.TestCheckResourceAttr( @@ -56,43 +62,48 @@ func TestAccPagerDutyUser_Basic(t *testing.T) { } func TestAccPagerDutyUserWithTeams_Basic(t *testing.T) { + username := fmt.Sprintf("tf-%s", acctest.RandString(5)) + email := fmt.Sprintf("%s@foo.com", username) + team1 := fmt.Sprintf("tf-%s", acctest.RandString(5)) + team2 := fmt.Sprintf("tf-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPagerDutyUserDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckPagerDutyUserWithTeamsConfig, + { + Config: testAccCheckPagerDutyUserWithTeamsConfig(team1, username, email), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyUserExists("pagerduty_user.foo"), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "name", "foo"), + "pagerduty_user.foo", "name", username), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "email", "foo@bar.com"), + "pagerduty_user.foo", "email", email), resource.TestCheckResourceAttr( "pagerduty_user.foo", "teams.#", "1"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyUserWithTeamsConfigUpdated, + { + Config: testAccCheckPagerDutyUserWithTeamsConfigUpdated(team1, team2, username, email), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyUserExists("pagerduty_user.foo"), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "name", "foo"), + "pagerduty_user.foo", "name", username), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "email", "foo@bar.com"), + "pagerduty_user.foo", "email", email), resource.TestCheckResourceAttr( "pagerduty_user.foo", "teams.#", "2"), ), }, - resource.TestStep{ - Config: testAccCheckPagerDutyUserWithNoTeamsConfig, + { + Config: testAccCheckPagerDutyUserWithNoTeamsConfig(team1, team2, username, email), Check: resource.ComposeTestCheckFunc( testAccCheckPagerDutyUserExists("pagerduty_user.foo"), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "name", "foo"), + "pagerduty_user.foo", "name", username), resource.TestCheckResourceAttr( - "pagerduty_user.foo", "email", "foo@bar.com"), + "pagerduty_user.foo", "email", email), resource.TestCheckResourceAttr( "pagerduty_user.foo", "teams.#", "0"), ), @@ -145,66 +156,75 @@ func testAccCheckPagerDutyUserExists(n string) resource.TestCheckFunc { } } -const testAccCheckPagerDutyUserConfig = ` +func testAccCheckPagerDutyUserConfig(username, email string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" color = "green" role = "user" job_title = "foo" description = "foo" +}`, username, email) } -` -const testAccCheckPagerDutyUserConfigUpdated = ` +func testAccCheckPagerDutyUserConfigUpdated(username, email string) string { + return fmt.Sprintf(` resource "pagerduty_user" "foo" { - name = "bar" - email = "bar@foo.com" + name = "%s" + email = "%s" color = "red" role = "team_responder" job_title = "bar" description = "bar" +}`, username, email) } -` -const testAccCheckPagerDutyUserWithTeamsConfig = ` +func testAccCheckPagerDutyUserWithTeamsConfig(team, username, email string) string { + return fmt.Sprintf(` resource "pagerduty_team" "foo" { - name = "Foo team" + name = "%s" } resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" teams = ["${pagerduty_team.foo.id}"] } -` -const testAccCheckPagerDutyUserWithTeamsConfigUpdated = ` +`, team, username, email) +} + +func testAccCheckPagerDutyUserWithTeamsConfigUpdated(team1, team2, username, email string) string { + return fmt.Sprintf(` resource "pagerduty_team" "foo" { - name = "Foo team" + name = "%s" } resource "pagerduty_team" "bar" { - name = "Bar team" + name = "%s" } resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" teams = ["${pagerduty_team.foo.id}", "${pagerduty_team.bar.id}"] } -` +`, team1, team2, username, email) +} -const testAccCheckPagerDutyUserWithNoTeamsConfig = ` +func testAccCheckPagerDutyUserWithNoTeamsConfig(team1, team2, username, email string) string { + return fmt.Sprintf(` resource "pagerduty_team" "foo" { - name = "Foo team" + name = "%s" } resource "pagerduty_team" "bar" { - name = "Bar team" + name = "%s" } resource "pagerduty_user" "foo" { - name = "foo" - email = "foo@bar.com" + name = "%s" + email = "%s" +} +`, team1, team2, username, email) } -`