From 4d89e32de5f017819e7cc481c30a90c3371aa843 Mon Sep 17 00:00:00 2001 From: Shotaro Kohama Date: Thu, 27 Jan 2022 10:19:01 -0800 Subject: [PATCH] feat: make schedule_layer's end nullable in json --- pagerduty/schedule.go | 3 ++- pagerduty/schedule_test.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pagerduty/schedule.go b/pagerduty/schedule.go index f526aaf..bcf5f3e 100644 --- a/pagerduty/schedule.go +++ b/pagerduty/schedule.go @@ -58,7 +58,8 @@ type ScheduleLayerEntry struct { // ScheduleLayer represents a schedule layer in a schedule type ScheduleLayer struct { - End string `json:"end,omitempty"` + // End should be nullable because if it's null, it means the layer does not end. + End *string `json:"end"` ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` RenderedCoveragePercentage float64 `json:"rendered_coverage_percentage,omitempty"` diff --git a/pagerduty/schedule_test.go b/pagerduty/schedule_test.go index 5a2f716..e27190c 100644 --- a/pagerduty/schedule_test.go +++ b/pagerduty/schedule_test.go @@ -110,8 +110,12 @@ func TestSchedulesUpdate(t *testing.T) { input := &Schedule{ Name: "foo", + ScheduleLayers: []*ScheduleLayer{ + &ScheduleLayer{ + Name: "Layer1", + }, + }, } - mux.HandleFunc("/schedules/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") v := new(SchedulePayload) @@ -119,7 +123,7 @@ func TestSchedulesUpdate(t *testing.T) { if !reflect.DeepEqual(v.Schedule, input) { t.Errorf("Request body = %+v, want %+v", v, input) } - w.Write([]byte(`{"schedule": {"name": "foo", "id": "1"}}`)) + w.Write([]byte(`{"schedule": {"name": "foo", "id": "1", "schedule_layers": [{"name": "Layer1", "End": null}]}}`)) }) resp, _, err := client.Schedules.Update("1", input, &UpdateScheduleOptions{}) @@ -130,6 +134,11 @@ func TestSchedulesUpdate(t *testing.T) { want := &Schedule{ Name: "foo", ID: "1", + ScheduleLayers: []*ScheduleLayer{ + &ScheduleLayer{ + Name: "Layer1", + }, + }, } if !reflect.DeepEqual(resp, want) {