github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/pagerduty/data_source_pagerduty_schedule_test.go (about) 1 package pagerduty 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccDataSourcePagerDutySchedule_Basic(t *testing.T) { 13 rName := acctest.RandString(5) 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 Steps: []resource.TestStep{ 18 resource.TestStep{ 19 Config: testAccDataSourcePagerDutyScheduleConfig(rName), 20 Check: resource.ComposeTestCheckFunc( 21 testAccDataSourcePagerDutySchedule("pagerduty_schedule.test", "data.pagerduty_schedule.by_name"), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 func testAccDataSourcePagerDutySchedule(src, n string) resource.TestCheckFunc { 29 return func(s *terraform.State) error { 30 31 srcR := s.RootModule().Resources[src] 32 srcA := srcR.Primary.Attributes 33 34 r := s.RootModule().Resources[n] 35 a := r.Primary.Attributes 36 37 if a["id"] == "" { 38 return fmt.Errorf("Expected to get a schedule ID from PagerDuty") 39 } 40 41 testAtts := []string{"id", "name"} 42 43 for _, att := range testAtts { 44 if a[att] != srcA[att] { 45 return fmt.Errorf("Expected the schedule %s to be: %s, but got: %s", att, srcA[att], a[att]) 46 } 47 } 48 49 return nil 50 } 51 } 52 53 func testAccDataSourcePagerDutyScheduleConfig(rName string) string { 54 return fmt.Sprintf(` 55 resource "pagerduty_user" "test" { 56 name = "TF User %[1]s" 57 email = "tf.%[1]s@example.com" 58 } 59 60 resource "pagerduty_schedule" "test" { 61 name = "TF Schedule %[1]s" 62 63 time_zone = "America/New_York" 64 65 layer { 66 name = "foo" 67 start = "2015-11-06T20:00:00-05:00" 68 rotation_virtual_start = "2015-11-06T20:00:00-05:00" 69 rotation_turn_length_seconds = 86400 70 users = ["${pagerduty_user.test.id}"] 71 72 restriction { 73 type = "weekly_restriction" 74 start_time_of_day = "08:00:00" 75 start_day_of_week = 5 76 duration_seconds = 32101 77 } 78 } 79 } 80 81 data "pagerduty_schedule" "by_name" { 82 name = "${pagerduty_schedule.test.name}" 83 } 84 `, rName) 85 }