mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
* 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
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package pagerduty
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccDataSourcePagerDutyEscalationPolicy_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))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccDataSourcePagerDutyEscalationPolicyConfig(username, email, escalationPolicy),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccDataSourcePagerDutyEscalationPolicy("pagerduty_escalation_policy.test", "data.pagerduty_escalation_policy.by_name"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccDataSourcePagerDutyEscalationPolicy(src, n string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
|
|
srcR := s.RootModule().Resources[src]
|
|
srcA := srcR.Primary.Attributes
|
|
|
|
r := s.RootModule().Resources[n]
|
|
a := r.Primary.Attributes
|
|
|
|
if a["id"] == "" {
|
|
return fmt.Errorf("Expected to get a escalation policy ID from PagerDuty")
|
|
}
|
|
|
|
testAtts := []string{"id", "name"}
|
|
|
|
for _, att := range testAtts {
|
|
if a[att] != srcA[att] {
|
|
return fmt.Errorf("Expected the escalation policy %s to be: %s, but got: %s", att, srcA[att], a[att])
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccDataSourcePagerDutyEscalationPolicyConfig(username, email, escalationPolicy string) string {
|
|
return fmt.Sprintf(`
|
|
resource "pagerduty_user" "test" {
|
|
name = "%s"
|
|
email = "%s"
|
|
}
|
|
|
|
resource "pagerduty_escalation_policy" "test" {
|
|
name = "%s"
|
|
num_loops = 2
|
|
|
|
rule {
|
|
escalation_delay_in_minutes = 10
|
|
|
|
target {
|
|
type = "user_reference"
|
|
id = "${pagerduty_user.test.id}"
|
|
}
|
|
}
|
|
}
|
|
|
|
data "pagerduty_escalation_policy" "by_name" {
|
|
name = "${pagerduty_escalation_policy.test.name}"
|
|
}
|
|
`, username, email, escalationPolicy)
|
|
}
|