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
This commit is contained in:
Alexander 2017-05-11 16:14:30 +02:00 committed by Clint
parent 51c99b6e82
commit 0736dde0f7
17 changed files with 453 additions and 284 deletions

View File

@ -10,13 +10,16 @@ import (
) )
func TestAccDataSourcePagerDutyEscalationPolicy_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccDataSourcePagerDutyEscalationPolicyConfig(rName), Config: testAccDataSourcePagerDutyEscalationPolicyConfig(username, email, escalationPolicy),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccDataSourcePagerDutyEscalationPolicy("pagerduty_escalation_policy.test", "data.pagerduty_escalation_policy.by_name"), 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(` return fmt.Sprintf(`
resource "pagerduty_user" "test" { resource "pagerduty_user" "test" {
name = "TF User %[1]s" name = "%s"
email = "tf.%[1]s@example.com" email = "%s"
} }
resource "pagerduty_escalation_policy" "test" { resource "pagerduty_escalation_policy" "test" {
name = "TF Escalation Policy %[1]v" name = "%s"
num_loops = 2 num_loops = 2
rule { rule {
@ -74,5 +77,5 @@ resource "pagerduty_escalation_policy" "test" {
data "pagerduty_escalation_policy" "by_name" { data "pagerduty_escalation_policy" "by_name" {
name = "${pagerduty_escalation_policy.test.name}" name = "${pagerduty_escalation_policy.test.name}"
} }
`, rName) `, username, email, escalationPolicy)
} }

View File

@ -10,13 +10,16 @@ import (
) )
func TestAccDataSourcePagerDutySchedule_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccDataSourcePagerDutyScheduleConfig(rName), Config: testAccDataSourcePagerDutyScheduleConfig(username, email, schedule),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccDataSourcePagerDutySchedule("pagerduty_schedule.test", "data.pagerduty_schedule.by_name"), 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(` return fmt.Sprintf(`
resource "pagerduty_user" "test" { resource "pagerduty_user" "test" {
name = "TF User %[1]s" name = "%s"
email = "tf.%[1]s@example.com" email = "%s"
} }
resource "pagerduty_schedule" "test" { resource "pagerduty_schedule" "test" {
name = "TF Schedule %[1]s" name = "%s"
time_zone = "America/New_York" time_zone = "America/New_York"
@ -81,5 +84,5 @@ resource "pagerduty_schedule" "test" {
data "pagerduty_schedule" "by_name" { data "pagerduty_schedule" "by_name" {
name = "${pagerduty_schedule.test.name}" name = "${pagerduty_schedule.test.name}"
} }
`, rName) `, username, email, schedule)
} }

View File

@ -10,13 +10,15 @@ import (
) )
func TestAccDataSourcePagerDutyUser_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccDataSourcePagerDutyUserConfig(rName), Config: testAccDataSourcePagerDutyUserConfig(username, email),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccDataSourcePagerDutyUser("pagerduty_user.test", "data.pagerduty_user.by_email"), 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(` return fmt.Sprintf(`
resource "pagerduty_user" "test" { resource "pagerduty_user" "test" {
name = "TF User %[1]s" name = "%s"
email = "tf.%[1]s@example.com" email = "%s"
} }
data "pagerduty_user" "by_email" { data "pagerduty_user" "by_email" {
email = "${pagerduty_user.test.email}" email = "${pagerduty_user.test.email}"
} }
`, rName) `, username, email)
} }

View File

@ -1,25 +1,29 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutyEscalationPolicy_import(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyEscalationPolicyConfig, Config: testAccCheckPagerDutyEscalationPolicyConfig(username, email, escalationPolicy),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_escalation_policy.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -1,25 +1,29 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutySchedule_import(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyUserDestroy, CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfig, Config: testAccCheckPagerDutyScheduleConfig(username, email, schedule),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_schedule.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -1,25 +1,31 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutyServiceIntegration_import(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy,
Steps: []resource.TestStep{ 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, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -1,25 +1,30 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutyService_import(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy, CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceConfig, Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_service.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },
@ -28,19 +33,22 @@ func TestAccPagerDutyService_import(t *testing.T) {
} }
func TestAccPagerDutyServiceWithIncidentUrgency_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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy, CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig, Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_service.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -1,25 +1,27 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutyTeam_import(t *testing.T) { func TestAccPagerDutyTeam_import(t *testing.T) {
resourceName := "pagerduty_team.foo" team := fmt.Sprintf("tf-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyTeamDestroy, CheckDestroy: testAccCheckPagerDutyTeamDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyTeamConfig, Config: testAccCheckPagerDutyTeamConfig(team),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_team.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -1,25 +1,28 @@
package pagerduty package pagerduty
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccPagerDutyUser_import(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyUserDestroy, CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyUserConfig, Config: testAccCheckPagerDutyUserConfig(username, email),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: "pagerduty_user.foo",
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },

View File

@ -29,6 +29,10 @@ func TestProviderImpl(t *testing.T) {
} }
func testAccPreCheck(t *testing.T) { func testAccPreCheck(t *testing.T) {
if v := os.Getenv("PAGERDUTY_PARALLEL"); v != "" {
t.Parallel()
}
if v := os.Getenv("PAGERDUTY_TOKEN"); v == "" { if v := os.Getenv("PAGERDUTY_TOKEN"); v == "" {
t.Fatal("PAGERDUTY_TOKEN must be set for acceptance tests") t.Fatal("PAGERDUTY_TOKEN must be set for acceptance tests")
} }

View File

@ -5,32 +5,36 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyAddon_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyAddonDestroy, CheckDestroy: testAccCheckPagerDutyAddonDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyAddonConfig, Config: testAccCheckPagerDutyAddonConfig(addon),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"), testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_addon.foo", "name", "Foo status page"), "pagerduty_addon.foo", "name", addon),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_addon.foo", "src", "https://intranet.foo.com/status"), "pagerduty_addon.foo", "src", "https://intranet.foo.com/status"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyAddonConfigUpdated, Config: testAccCheckPagerDutyAddonConfigUpdated(addonUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"), testAccCheckPagerDutyAddonExists("pagerduty_addon.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_addon.foo", "name", "Bar status page"), "pagerduty_addon.foo", "name", addonUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_addon.foo", "src", "https://intranet.bar.com/status"), "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" { resource "pagerduty_addon" "foo" {
name = "Foo status page" name = "%s"
src = "https://intranet.foo.com/status" src = "https://intranet.foo.com/status"
} }
` `, addon)
}
const testAccCheckPagerDutyAddonConfigUpdated = ` func testAccCheckPagerDutyAddonConfigUpdated(addon string) string {
return fmt.Sprintf(`
resource "pagerduty_addon" "foo" { resource "pagerduty_addon" "foo" {
name = "Bar status page" name = "%s"
src = "https://intranet.bar.com/status" src = "https://intranet.bar.com/status"
} }
` `, addon)
}

View File

@ -5,22 +5,28 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyEscalationPolicyConfig, Config: testAccCheckPagerDutyEscalationPolicyConfig(username, email, escalationPolicy),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "name", "foo"), "pagerduty_escalation_policy.foo", "name", escalationPolicy),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "description", "foo"), "pagerduty_escalation_policy.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -31,12 +37,13 @@ func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) {
"pagerduty_escalation_policy.foo", "rule.0.escalation_delay_in_minutes", "10"), "pagerduty_escalation_policy.foo", "rule.0.escalation_delay_in_minutes", "10"),
), ),
}, },
resource.TestStep{
Config: testAccCheckPagerDutyEscalationPolicyConfigUpdated, {
Config: testAccCheckPagerDutyEscalationPolicyConfigUpdated(username, email, escalationPolicyUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "name", "bar"), "pagerduty_escalation_policy.foo", "name", escalationPolicyUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "description", "bar"), "pagerduty_escalation_policy.foo", "description", "bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -54,17 +61,23 @@ func TestAccPagerDutyEscalationPolicy_Basic(t *testing.T) {
} }
func TestAccPagerDutyEscalationPolicyWithTeams_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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy, CheckDestroy: testAccCheckPagerDutyEscalationPolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfig, Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfig(username, email, team, escalationPolicy),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "name", "foo"), "pagerduty_escalation_policy.foo", "name", escalationPolicy),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "description", "foo"), "pagerduty_escalation_policy.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -77,12 +90,12 @@ func TestAccPagerDutyEscalationPolicyWithTeams_Basic(t *testing.T) {
"pagerduty_escalation_policy.foo", "teams.#", "1"), "pagerduty_escalation_policy.foo", "teams.#", "1"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated, Config: testAccCheckPagerDutyEscalationPolicyWithTeamsConfigUpdated(username, email, team, escalationPolicyUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"), testAccCheckPagerDutyEscalationPolicyExists("pagerduty_escalation_policy.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "name", "bar"), "pagerduty_escalation_policy.foo", "name", escalationPolicyUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_escalation_policy.foo", "description", "bar"), "pagerduty_escalation_policy.foo", "description", "bar"),
resource.TestCheckResourceAttr( 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -154,7 +168,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
num_loops = 1 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -180,7 +196,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -215,12 +233,12 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_team" "foo" { resource "pagerduty_team" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
num_loops = 1 num_loops = 1
teams = ["${pagerduty_team.foo.id}"] 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -247,12 +267,12 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_team" "foo" { resource "pagerduty_team" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -274,4 +294,5 @@ resource "pagerduty_escalation_policy" "foo" {
} }
} }
} }
` `, name, email, team, escalationPolicy)
}

View File

@ -5,22 +5,28 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutySchedule_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyScheduleDestroy, CheckDestroy: testAccCheckPagerDutyScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfig, Config: testAccCheckPagerDutyScheduleConfig(username, email, schedule),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "name", "foo"), "pagerduty_schedule.foo", "name", schedule),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "description", "foo"), "pagerduty_schedule.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -31,12 +37,12 @@ func TestAccPagerDutySchedule_Basic(t *testing.T) {
"pagerduty_schedule.foo", "layer.0.name", "foo"), "pagerduty_schedule.foo", "layer.0.name", "foo"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfigUpdated, Config: testAccCheckPagerDutyScheduleConfigUpdated(username, email, scheduleUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "name", "bar"), "pagerduty_schedule.foo", "name", scheduleUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "description", "Managed by Terraform"), "pagerduty_schedule.foo", "description", "Managed by Terraform"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -52,17 +58,22 @@ func TestAccPagerDutySchedule_Basic(t *testing.T) {
} }
func TestAccPagerDutySchedule_BasicWeek(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyScheduleDestroy, CheckDestroy: testAccCheckPagerDutyScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfigWeek, Config: testAccCheckPagerDutyScheduleConfigWeek(username, email, schedule),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "name", "foo"), "pagerduty_schedule.foo", "name", schedule),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "description", "foo"), "pagerduty_schedule.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -75,12 +86,12 @@ func TestAccPagerDutySchedule_BasicWeek(t *testing.T) {
"pagerduty_schedule.foo", "layer.0.restriction.0.start_day_of_week", "1"), "pagerduty_schedule.foo", "layer.0.restriction.0.start_day_of_week", "1"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfigWeekUpdated, Config: testAccCheckPagerDutyScheduleConfigWeekUpdated(username, email, scheduleUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "name", "bar"), "pagerduty_schedule.foo", "name", scheduleUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "description", "Managed by Terraform"), "pagerduty_schedule.foo", "description", "Managed by Terraform"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -98,17 +109,21 @@ func TestAccPagerDutySchedule_BasicWeek(t *testing.T) {
} }
func TestAccPagerDutySchedule_Multi(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyScheduleDestroy, CheckDestroy: testAccCheckPagerDutyScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyScheduleConfigMulti, Config: testAccCheckPagerDutyScheduleConfigMulti(username, email, schedule),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"), testAccCheckPagerDutyScheduleExists("pagerduty_schedule.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "name", "foo"), "pagerduty_schedule.foo", "name", schedule),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "description", "foo"), "pagerduty_schedule.foo", "description", "foo"),
resource.TestCheckResourceAttr( 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_schedule" "foo" { resource "pagerduty_schedule" "foo" {
name = "foo" name = "%s"
time_zone = "Europe/Berlin" time_zone = "Europe/Berlin"
description = "foo" 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_schedule" "foo" { resource "pagerduty_schedule" "foo" {
name = "bar" name = "%s"
time_zone = "America/New_York" 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_schedule" "foo" { resource "pagerduty_schedule" "foo" {
name = "foo" name = "%s"
time_zone = "Europe/Berlin" time_zone = "Europe/Berlin"
description = "foo" 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_schedule" "foo" { resource "pagerduty_schedule" "foo" {
name = "bar" name = "%s"
time_zone = "America/New_York" 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_schedule" "foo" { resource "pagerduty_schedule" "foo" {
name = "foo" name = "%s"
time_zone = "America/New_York" time_zone = "America/New_York"
description = "foo" description = "foo"
@ -383,4 +407,5 @@ resource "pagerduty_schedule" "foo" {
} }
} }
} }
` `, username, email, schedule)
}

View File

@ -5,34 +5,42 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyServiceIntegration_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceIntegrationConfig, Config: testAccCheckPagerDutyServiceIntegrationConfig(username, email, escalationPolicy, service, serviceIntegration),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "name", "foo"), "pagerduty_service_integration.foo", "name", serviceIntegration),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "vendor", "PAM4FGS"), "pagerduty_service_integration.foo", "vendor", "PAM4FGS"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceIntegrationConfigUpdated, Config: testAccCheckPagerDutyServiceIntegrationConfigUpdated(username, email, escalationPolicy, service, serviceIntegrationUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "name", "bar"), "pagerduty_service_integration.foo", "name", serviceIntegrationUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -44,27 +52,34 @@ func TestAccPagerDutyServiceIntegration_Basic(t *testing.T) {
} }
func TestAccPagerDutyServiceIntegrationGeneric_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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy, CheckDestroy: testAccCheckPagerDutyServiceIntegrationDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceIntegrationGenericConfig, Config: testAccCheckPagerDutyServiceIntegrationGenericConfig(username, email, escalationPolicy, service, serviceIntegration),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "name", "foo"), "pagerduty_service_integration.foo", "name", serviceIntegration),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), "pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated, Config: testAccCheckPagerDutyServiceIntegrationGenericConfigUpdated(username, email, escalationPolicy, service, serviceIntegrationUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"), testAccCheckPagerDutyServiceIntegrationExists("pagerduty_service_integration.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "name", "bar"), "pagerduty_service_integration.foo", "name", serviceIntegrationUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"), "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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
num_loops = 1 num_loops = 1
@ -142,7 +158,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
auto_resolve_timeout = 1800 auto_resolve_timeout = 1800
acknowledgement_timeout = 1800 acknowledgement_timeout = 1800
@ -159,16 +175,18 @@ data "pagerduty_vendor" "datadog" {
} }
resource "pagerduty_service_integration" "foo" { resource "pagerduty_service_integration" "foo" {
name = "foo" name = "%s"
service = "${pagerduty_service.foo.id}" service = "${pagerduty_service.foo.id}"
vendor = "${data.pagerduty_vendor.datadog.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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -176,7 +194,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -191,7 +209,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
auto_resolve_timeout = 3600 auto_resolve_timeout = 3600
acknowledgement_timeout = 3600 acknowledgement_timeout = 3600
@ -208,20 +226,22 @@ data "pagerduty_vendor" "datadog" {
} }
resource "pagerduty_service_integration" "foo" { resource "pagerduty_service_integration" "foo" {
name = "bar" name = "%s"
service = "${pagerduty_service.foo.id}" service = "${pagerduty_service.foo.id}"
vendor = "${data.pagerduty_vendor.datadog.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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
num_loops = 1 num_loops = 1
@ -236,7 +256,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
auto_resolve_timeout = 1800 auto_resolve_timeout = 1800
acknowledgement_timeout = 1800 acknowledgement_timeout = 1800
@ -249,16 +269,18 @@ resource "pagerduty_service" "foo" {
} }
resource "pagerduty_service_integration" "foo" { resource "pagerduty_service_integration" "foo" {
name = "foo" name = "%s"
service = "${pagerduty_service.foo.id}" service = "${pagerduty_service.foo.id}"
type = "generic_events_api_inbound_integration" 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -266,7 +288,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -281,7 +303,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
auto_resolve_timeout = 3600 auto_resolve_timeout = 3600
acknowledgement_timeout = 3600 acknowledgement_timeout = 3600
@ -294,8 +316,9 @@ resource "pagerduty_service" "foo" {
} }
resource "pagerduty_service_integration" "foo" { resource "pagerduty_service_integration" "foo" {
name = "bar" name = "%s"
service = "${pagerduty_service.foo.id}" service = "${pagerduty_service.foo.id}"
type = "generic_events_api_inbound_integration" type = "generic_events_api_inbound_integration"
} }
` `, username, email, escalationPolicy, service, serviceIntegration)
}

View File

@ -5,22 +5,29 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyService_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy, CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceConfig, Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "foo"), "pagerduty_service.foo", "name", service),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "foo"), "pagerduty_service.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -35,12 +42,12 @@ func TestAccPagerDutyService_Basic(t *testing.T) {
"pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceConfigUpdated, Config: testAccCheckPagerDutyServiceConfigUpdated(username, email, escalationPolicy, serviceUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "bar"), "pagerduty_service.foo", "name", serviceUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "bar"), "pagerduty_service.foo", "description", "bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -60,17 +67,23 @@ func TestAccPagerDutyService_Basic(t *testing.T) {
} }
func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy, CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig, Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "foo"), "pagerduty_service.foo", "name", service),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "foo"), "pagerduty_service.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -127,12 +140,12 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) {
"pagerduty_service.foo", "support_hours.0.type", "fixed_time_per_day"), "pagerduty_service.foo", "support_hours.0.type", "fixed_time_per_day"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated, Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, serviceUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "bar"), "pagerduty_service.foo", "name", serviceUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "bar bar bar"), "pagerduty_service.foo", "description", "bar bar bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -194,17 +207,23 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) {
} }
func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy, CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceConfig, Config: testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "foo"), "pagerduty_service.foo", "name", service),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "foo"), "pagerduty_service.foo", "description", "foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -219,12 +238,12 @@ func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(t *testing.T)
"pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated, Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, serviceUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", "bar"), "pagerduty_service.foo", "name", serviceUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "bar bar bar"), "pagerduty_service.foo", "description", "bar bar bar"),
resource.TestCheckResourceAttr( 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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@example.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -339,7 +359,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
rule { rule {
@ -352,7 +372,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
auto_resolve_timeout = 1800 auto_resolve_timeout = 1800
acknowledgement_timeout = 1800 acknowledgement_timeout = 1800
@ -362,12 +382,14 @@ resource "pagerduty_service" "foo" {
urgency = "high" urgency = "high"
} }
} }
` `, username, email, escalationPolicy, service)
}
const testAccCheckPagerDutyServiceConfigUpdated = ` func testAccCheckPagerDutyServiceConfigUpdated(username, email, escalationPolicy, service string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@example.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -375,7 +397,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -389,7 +411,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
auto_resolve_timeout = 3600 auto_resolve_timeout = 3600
acknowledgement_timeout = 3600 acknowledgement_timeout = 3600
@ -400,12 +422,14 @@ resource "pagerduty_service" "foo" {
urgency = "high" urgency = "high"
} }
} }
` `, username, email, escalationPolicy, service)
}
const testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig = ` func testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig(username, email, escalationPolicy, service string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@example.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -413,7 +437,7 @@ resource "pagerduty_user" "foo" {
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -427,7 +451,7 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
auto_resolve_timeout = 1800 auto_resolve_timeout = 1800
acknowledgement_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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@example.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
@ -476,7 +502,7 @@ const testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated = `
} }
resource "pagerduty_escalation_policy" "foo" { resource "pagerduty_escalation_policy" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
num_loops = 2 num_loops = 2
@ -490,12 +516,12 @@ resource "pagerduty_escalation_policy" "foo" {
} }
resource "pagerduty_service" "foo" { resource "pagerduty_service" "foo" {
name = "bar" name = "%s"
description = "bar bar bar" description = "bar bar bar"
auto_resolve_timeout = 3600 auto_resolve_timeout = 3600
acknowledgement_timeout = 3600 acknowledgement_timeout = 3600
escalation_policy = "${pagerduty_escalation_policy.foo.id}" escalation_policy = "${pagerduty_escalation_policy.foo.id}"
incident_urgency_rule { incident_urgency_rule {
type = "use_support_hours" type = "use_support_hours"
during_support_hours { during_support_hours {
@ -525,4 +551,5 @@ resource "pagerduty_service" "foo" {
} }
} }
} }
` `, username, email, escalationPolicy, service)
}

View File

@ -5,32 +5,36 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyTeam_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyTeamDestroy, CheckDestroy: testAccCheckPagerDutyTeamDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyTeamConfig, Config: testAccCheckPagerDutyTeamConfig(team),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyTeamExists("pagerduty_team.foo"), testAccCheckPagerDutyTeamExists("pagerduty_team.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_team.foo", "name", "foo"), "pagerduty_team.foo", "name", team),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_team.foo", "description", "foo"), "pagerduty_team.foo", "description", "foo"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyTeamConfigUpdated, Config: testAccCheckPagerDutyTeamConfigUpdated(teamUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyTeamExists("pagerduty_team.foo"), testAccCheckPagerDutyTeamExists("pagerduty_team.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_team.foo", "name", "bar"), "pagerduty_team.foo", "name", teamUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_team.foo", "description", "bar"), "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" { resource "pagerduty_team" "foo" {
name = "foo" name = "%s"
description = "foo" description = "foo"
}`, team)
} }
`
const testAccCheckPagerDutyTeamConfigUpdated = ` func testAccCheckPagerDutyTeamConfigUpdated(team string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "foo" { resource "pagerduty_team" "foo" {
name = "bar" name = "%s"
description = "bar" description = "bar"
}`, team)
} }
`

View File

@ -5,24 +5,30 @@ import (
"testing" "testing"
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccPagerDutyUser_Basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyUserDestroy, CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyUserConfig, Config: testAccCheckPagerDutyUserConfig(username, email),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"), testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", "foo"), "pagerduty_user.foo", "name", username),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", "foo@bar.com"), "pagerduty_user.foo", "email", email),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "color", "green"), "pagerduty_user.foo", "color", "green"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -33,14 +39,14 @@ func TestAccPagerDutyUser_Basic(t *testing.T) {
"pagerduty_user.foo", "description", "foo"), "pagerduty_user.foo", "description", "foo"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyUserConfigUpdated, Config: testAccCheckPagerDutyUserConfigUpdated(usernameUpdated, emailUpdated),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"), testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", "bar"), "pagerduty_user.foo", "name", usernameUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", "bar@foo.com"), "pagerduty_user.foo", "email", emailUpdated),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "color", "red"), "pagerduty_user.foo", "color", "red"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -56,43 +62,48 @@ func TestAccPagerDutyUser_Basic(t *testing.T) {
} }
func TestAccPagerDutyUserWithTeams_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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyUserDestroy, CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccCheckPagerDutyUserWithTeamsConfig, Config: testAccCheckPagerDutyUserWithTeamsConfig(team1, username, email),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"), testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", "foo"), "pagerduty_user.foo", "name", username),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", "foo@bar.com"), "pagerduty_user.foo", "email", email),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "teams.#", "1"), "pagerduty_user.foo", "teams.#", "1"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyUserWithTeamsConfigUpdated, Config: testAccCheckPagerDutyUserWithTeamsConfigUpdated(team1, team2, username, email),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"), testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", "foo"), "pagerduty_user.foo", "name", username),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", "foo@bar.com"), "pagerduty_user.foo", "email", email),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "teams.#", "2"), "pagerduty_user.foo", "teams.#", "2"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckPagerDutyUserWithNoTeamsConfig, Config: testAccCheckPagerDutyUserWithNoTeamsConfig(team1, team2, username, email),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyUserExists("pagerduty_user.foo"), testAccCheckPagerDutyUserExists("pagerduty_user.foo"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "name", "foo"), "pagerduty_user.foo", "name", username),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "email", "foo@bar.com"), "pagerduty_user.foo", "email", email),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"pagerduty_user.foo", "teams.#", "0"), "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" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
color = "green" color = "green"
role = "user" role = "user"
job_title = "foo" job_title = "foo"
description = "foo" description = "foo"
}`, username, email)
} }
`
const testAccCheckPagerDutyUserConfigUpdated = ` func testAccCheckPagerDutyUserConfigUpdated(username, email string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "bar" name = "%s"
email = "bar@foo.com" email = "%s"
color = "red" color = "red"
role = "team_responder" role = "team_responder"
job_title = "bar" job_title = "bar"
description = "bar" description = "bar"
}`, username, email)
} }
`
const testAccCheckPagerDutyUserWithTeamsConfig = ` func testAccCheckPagerDutyUserWithTeamsConfig(team, username, email string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "foo" { resource "pagerduty_team" "foo" {
name = "Foo team" name = "%s"
} }
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
teams = ["${pagerduty_team.foo.id}"] teams = ["${pagerduty_team.foo.id}"]
} }
` `, team, username, email)
const testAccCheckPagerDutyUserWithTeamsConfigUpdated = ` }
func testAccCheckPagerDutyUserWithTeamsConfigUpdated(team1, team2, username, email string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "foo" { resource "pagerduty_team" "foo" {
name = "Foo team" name = "%s"
} }
resource "pagerduty_team" "bar" { resource "pagerduty_team" "bar" {
name = "Bar team" name = "%s"
} }
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
teams = ["${pagerduty_team.foo.id}", "${pagerduty_team.bar.id}"] 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" { resource "pagerduty_team" "foo" {
name = "Foo team" name = "%s"
} }
resource "pagerduty_team" "bar" { resource "pagerduty_team" "bar" {
name = "Bar team" name = "%s"
} }
resource "pagerduty_user" "foo" { resource "pagerduty_user" "foo" {
name = "foo" name = "%s"
email = "foo@bar.com" email = "%s"
}
`, team1, team2, username, email)
} }
`