2017-02-01 21:01:46 +01:00
|
|
|
package pagerduty
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccDataSourcePagerDutySchedule_Basic(t *testing.T) {
|
2017-05-11 16:14:30 +02:00
|
|
|
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
|
|
|
|
email := fmt.Sprintf("%s@foo.com", username)
|
|
|
|
schedule := fmt.Sprintf("tf-%s", acctest.RandString(5))
|
|
|
|
|
2017-02-01 21:01:46 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
2017-05-11 16:14:30 +02:00
|
|
|
{
|
|
|
|
Config: testAccDataSourcePagerDutyScheduleConfig(username, email, schedule),
|
2017-02-01 21:01:46 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccDataSourcePagerDutySchedule("pagerduty_schedule.test", "data.pagerduty_schedule.by_name"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccDataSourcePagerDutySchedule(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 schedule ID from PagerDuty")
|
|
|
|
}
|
|
|
|
|
|
|
|
testAtts := []string{"id", "name"}
|
|
|
|
|
|
|
|
for _, att := range testAtts {
|
|
|
|
if a[att] != srcA[att] {
|
|
|
|
return fmt.Errorf("Expected the schedule %s to be: %s, but got: %s", att, srcA[att], a[att])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:14:30 +02:00
|
|
|
func testAccDataSourcePagerDutyScheduleConfig(username, email, schedule string) string {
|
2017-02-01 21:01:46 +01:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "pagerduty_user" "test" {
|
2017-05-11 16:14:30 +02:00
|
|
|
name = "%s"
|
|
|
|
email = "%s"
|
2017-02-01 21:01:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "pagerduty_schedule" "test" {
|
2017-05-11 16:14:30 +02:00
|
|
|
name = "%s"
|
2017-02-01 21:01:46 +01:00
|
|
|
|
|
|
|
time_zone = "America/New_York"
|
|
|
|
|
|
|
|
layer {
|
|
|
|
name = "foo"
|
|
|
|
start = "2015-11-06T20:00:00-05:00"
|
|
|
|
rotation_virtual_start = "2015-11-06T20:00:00-05:00"
|
|
|
|
rotation_turn_length_seconds = 86400
|
|
|
|
users = ["${pagerduty_user.test.id}"]
|
|
|
|
|
|
|
|
restriction {
|
|
|
|
type = "weekly_restriction"
|
|
|
|
start_time_of_day = "08:00:00"
|
|
|
|
start_day_of_week = 5
|
|
|
|
duration_seconds = 32101
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "pagerduty_schedule" "by_name" {
|
|
|
|
name = "${pagerduty_schedule.test.name}"
|
|
|
|
}
|
2017-05-11 16:14:30 +02:00
|
|
|
`, username, email, schedule)
|
2017-02-01 21:01:46 +01:00
|
|
|
}
|