Skip to content

Commit

Permalink
Update schedule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heimweh committed Dec 16, 2016
1 parent 2c7ce0d commit caeae7c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
49 changes: 47 additions & 2 deletions builtin/providers/pagerduty/resource_pagerduty_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,57 @@ func TestAccPagerDutySchedule_Multi(t *testing.T) {
"pagerduty_schedule.foo", "description", "foo"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "time_zone", "America/New_York"),

resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.#", "3"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.name", "foo"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.restriction.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.restriction.0.duration_seconds", "32101"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.restriction.0.start_time_of_day", "08:00:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.rotation_turn_length_seconds", "86400"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.rotation_virtual_start", "2015-11-06T20:00:00-05:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.0.users.#", "1"),

resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.name", "bar"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.restriction.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.restriction.0.duration_seconds", "32101"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.restriction.0.start_time_of_day", "08:00:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.restriction.0.start_day_of_week", "5"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.rotation_turn_length_seconds", "86400"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.rotation_virtual_start", "2015-11-06T20:00:00-05:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.1.users.#", "1"),

resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.name", "foobar"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.restriction.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.restriction.0.duration_seconds", "32101"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.restriction.0.start_time_of_day", "08:00:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.restriction.0.start_day_of_week", "1"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.rotation_turn_length_seconds", "86400"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.rotation_virtual_start", "2015-11-06T20:00:00-05:00"),
resource.TestCheckResourceAttr(
"pagerduty_schedule.foo", "layer.2.users.#", "1"),
),
},
},
Expand Down Expand Up @@ -212,8 +255,9 @@ resource "pagerduty_schedule" "foo" {
users = ["${pagerduty_user.foo.id}"]
restriction {
type = "daily_restriction"
type = "weekly_restriction"
start_time_of_day = "08:00:00"
start_day_of_week = 5
duration_seconds = 32101
}
}
Expand All @@ -226,8 +270,9 @@ resource "pagerduty_schedule" "foo" {
users = ["${pagerduty_user.foo.id}"]
restriction {
type = "daily_restriction"
type = "weekly_restriction"
start_time_of_day = "08:00:00"
start_day_of_week = 1
duration_seconds = 32101
}
}
Expand Down
12 changes: 9 additions & 3 deletions builtin/providers/pagerduty/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func expandScheduleLayers(list []interface{}) []pagerduty.ScheduleLayer {
pagerduty.Restriction{
Type: restriction["type"].(string),
StartTimeOfDay: restriction["start_time_of_day"].(string),
StartDayOfWeek: restriction["start_day_of_week"].(int),
StartDayOfWeek: uint(restriction["start_day_of_week"].(int)),
DurationSeconds: uint(restriction["duration_seconds"].(int)),
},
)
Expand Down Expand Up @@ -147,11 +147,17 @@ func flattenScheduleLayers(list []pagerduty.ScheduleLayer) []map[string]interfac
if len(i.Restrictions) > 0 {
restrictions := make([]map[string]interface{}, 0, len(i.Restrictions))
for _, r := range i.Restrictions {
restrictions = append(restrictions, map[string]interface{}{
restriction := map[string]interface{}{
"duration_seconds": r.DurationSeconds,
"start_time_of_day": r.StartTimeOfDay,
"type": r.Type,
})
}

if r.StartDayOfWeek > 0 {
restriction["start_day_of_week"] = r.StartDayOfWeek
}

restrictions = append(restrictions, restriction)
}
r["restriction"] = restrictions
}
Expand Down

0 comments on commit caeae7c

Please sign in to comment.