From f80c46c198f4b70eb70e21eefc0f6aa15b638338 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Wed, 15 May 2019 09:01:20 -0500 Subject: [PATCH] should update the passed downtime struct when updating this contains the downtime type information along with potentially sanitizing replacing fields in the future downtimes will be immutable and this is forwards compatible --- downtimes.go | 2 +- integration/downtime_test.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/downtimes.go b/downtimes.go index b6bf5cc..118e5d2 100644 --- a/downtimes.go +++ b/downtimes.go @@ -56,7 +56,7 @@ func (client *Client) CreateDowntime(downtime *Downtime) (*Downtime, error) { // and sends it back to the server. func (client *Client) UpdateDowntime(downtime *Downtime) error { return client.doJsonRequest("PUT", fmt.Sprintf("/v1/downtime/%d", *downtime.Id), - downtime, nil) + downtime, downtime) } // Getdowntime retrieves an downtime by identifier. diff --git a/integration/downtime_test.go b/integration/downtime_test.go index 18c8cad..f0f2a7a 100644 --- a/integration/downtime_test.go +++ b/integration/downtime_test.go @@ -52,7 +52,10 @@ func TestDowntimeLinkedToMonitorCreateAndDelete(t *testing.T) { func TestDowntimeUpdate(t *testing.T) { downtime := createTestDowntime(t) + originalID := int(downtime.GetId()) + // changing the scope will cause the downtime to be replaced in the future + // this test should be updated to validate this downtime.Scope = []string{"env:downtime_test", "env:downtime_test2"} defer cleanUpDowntime(t, *downtime.Id) @@ -65,8 +68,22 @@ func TestDowntimeUpdate(t *testing.T) { t.Fatalf("Retrieving a downtime failed when it shouldn't: %s", err) } - assert.Equal(t, downtime, actual) - + // uncomment once immutable to validate it changed to NotEqual + assert.Equal(t, originalID, actual.GetId()) + assert.Equal(t, downtime.GetActive(), actual.GetActive()) + assert.Equal(t, downtime.GetCanceled(), actual.GetCanceled()) + assert.Equal(t, downtime.GetDisabled(), actual.GetDisabled()) + assert.Equal(t, downtime.GetEnd(), actual.GetEnd()) + assert.Equal(t, downtime.GetMessage(), actual.GetMessage()) + assert.Equal(t, downtime.GetMonitorId(), actual.GetMonitorId()) + assert.Equal(t, downtime.MonitorTags, actual.MonitorTags) + assert.Equal(t, downtime.GetParentId(), actual.GetParentId()) + // timezone will be automatically updated to UTC + assert.Equal(t, "UTC", actual.GetTimezone()) + assert.Equal(t, downtime.GetRecurrence(), actual.GetRecurrence()) + assert.EqualValues(t, downtime.Scope, actual.Scope) + // in the future the replaced downtime will have an updated start time, flip this to NotEqual + assert.Equal(t, downtime.GetStart(), actual.GetStart()) } func TestDowntimeGet(t *testing.T) {