From 251ae25f5a8c8b2bfa4962caafd8b1b93165e5d2 Mon Sep 17 00:00:00 2001 From: Jesse Whitham Date: Tue, 3 Sep 2019 17:20:22 +1200 Subject: [PATCH 1/2] Fix Precision issue with Durations * CloudWatchEvents seem to return with precision 60.0 instead of 60 * Change tests to match * Change types to float64 --- events/duration.go | 4 ++-- events/testdata/codebuild-phase-change.json | 22 ++++++++++----------- events/testdata/codebuild-state-change.json | 20 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/events/duration.go b/events/duration.go index 6091b2f7..1c61d7a9 100644 --- a/events/duration.go +++ b/events/duration.go @@ -9,7 +9,7 @@ import ( type DurationSeconds time.Duration func (duration *DurationSeconds) UnmarshalJSON(data []byte) error { - var seconds int64 + var seconds float64 if err := json.Unmarshal(data, &seconds); err != nil { return err } @@ -26,7 +26,7 @@ func (duration DurationSeconds) MarshalJSON() ([]byte, error) { type DurationMinutes time.Duration func (duration *DurationMinutes) UnmarshalJSON(data []byte) error { - var minutes int64 + var minutes float64 if err := json.Unmarshal(data, &minutes); err != nil { return err } diff --git a/events/testdata/codebuild-phase-change.json b/events/testdata/codebuild-phase-change.json index eb955368..8e06021d 100644 --- a/events/testdata/codebuild-phase-change.json +++ b/events/testdata/codebuild-phase-change.json @@ -27,7 +27,7 @@ "type": "LINUX_CONTAINER", "environment-variables": [] }, - "timeout-in-minutes": 60, + "timeout-in-minutes": 60.0, "build-complete": true, "initiator": "MyCodeBuildDemoUser", "build-start-time": "Sep 1, 2017 4:12:29 PM", @@ -45,7 +45,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:12:29 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "SUBMITTED", "phase-status": "SUCCEEDED" }, @@ -53,7 +53,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:13:05 PM", - "duration-in-seconds": 36, + "duration-in-seconds": 36.0, "phase-type": "PROVISIONING", "phase-status": "SUCCEEDED" }, @@ -61,7 +61,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:05 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 4, + "duration-in-seconds": 4.0, "phase-type": "DOWNLOAD_SOURCE", "phase-status": "SUCCEEDED" }, @@ -69,7 +69,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "INSTALL", "phase-status": "SUCCEEDED" }, @@ -77,7 +77,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "PRE_BUILD", "phase-status": "SUCCEEDED" }, @@ -85,7 +85,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 70, + "duration-in-seconds": 70.0, "phase-type": "BUILD", "phase-status": "SUCCEEDED" }, @@ -93,7 +93,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "POST_BUILD", "phase-status": "SUCCEEDED" }, @@ -101,7 +101,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "UPLOAD_ARTIFACTS", "phase-status": "SUCCEEDED" }, @@ -109,7 +109,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:26 PM", - "duration-in-seconds": 4, + "duration-in-seconds": 4.0, "phase-type": "FINALIZING", "phase-status": "SUCCEEDED" }, @@ -120,7 +120,7 @@ ] }, "completed-phase-status": "SUCCEEDED", - "completed-phase-duration-seconds": 4, + "completed-phase-duration-seconds": 4.0, "version": "1", "completed-phase-start": "Sep 1, 2017 4:14:21 PM", "completed-phase-end": "Sep 1, 2017 4:14:26 PM" diff --git a/events/testdata/codebuild-state-change.json b/events/testdata/codebuild-state-change.json index cecfb06c..2169fc8e 100644 --- a/events/testdata/codebuild-state-change.json +++ b/events/testdata/codebuild-state-change.json @@ -32,7 +32,7 @@ } ] }, - "timeout-in-minutes": 60, + "timeout-in-minutes": 60.0, "build-complete": true, "initiator": "MyCodeBuildDemoUser", "build-start-time": "Sep 1, 2017 4:12:29 PM", @@ -50,7 +50,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:12:29 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "SUBMITTED", "phase-status": "SUCCEEDED" }, @@ -58,7 +58,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:13:05 PM", - "duration-in-seconds": 36, + "duration-in-seconds": 36.0, "phase-type": "PROVISIONING", "phase-status": "SUCCEEDED" }, @@ -66,7 +66,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:05 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 4, + "duration-in-seconds": 4.0, "phase-type": "DOWNLOAD_SOURCE", "phase-status": "SUCCEEDED" }, @@ -74,7 +74,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "INSTALL", "phase-status": "SUCCEEDED" }, @@ -82,7 +82,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "PRE_BUILD", "phase-status": "SUCCEEDED" }, @@ -90,7 +90,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 70, + "duration-in-seconds": 70.0, "phase-type": "BUILD", "phase-status": "SUCCEEDED" }, @@ -98,7 +98,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "POST_BUILD", "phase-status": "SUCCEEDED" }, @@ -106,7 +106,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0, + "duration-in-seconds": 0.0, "phase-type": "UPLOAD_ARTIFACTS", "phase-status": "SUCCEEDED" }, @@ -114,7 +114,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:26 PM", - "duration-in-seconds": 4, + "duration-in-seconds": 4.0, "phase-type": "FINALIZING", "phase-status": "SUCCEEDED" }, From 096851edec6a299548ad3146893b75b71cfa0b5d Mon Sep 17 00:00:00 2001 From: Jesse Whitham Date: Wed, 4 Sep 2019 09:42:38 +1200 Subject: [PATCH 2/2] Mix ints and floats --- events/testdata/codebuild-phase-change.json | 10 +++++----- events/testdata/codebuild-state-change.json | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/events/testdata/codebuild-phase-change.json b/events/testdata/codebuild-phase-change.json index 8e06021d..e5744ae2 100644 --- a/events/testdata/codebuild-phase-change.json +++ b/events/testdata/codebuild-phase-change.json @@ -53,7 +53,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:13:05 PM", - "duration-in-seconds": 36.0, + "duration-in-seconds": 36, "phase-type": "PROVISIONING", "phase-status": "SUCCEEDED" }, @@ -69,7 +69,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0.0, + "duration-in-seconds": 0, "phase-type": "INSTALL", "phase-status": "SUCCEEDED" }, @@ -85,7 +85,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 70.0, + "duration-in-seconds": 70, "phase-type": "BUILD", "phase-status": "SUCCEEDED" }, @@ -101,7 +101,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0.0, + "duration-in-seconds": 0, "phase-type": "UPLOAD_ARTIFACTS", "phase-status": "SUCCEEDED" }, @@ -125,4 +125,4 @@ "completed-phase-start": "Sep 1, 2017 4:14:21 PM", "completed-phase-end": "Sep 1, 2017 4:14:26 PM" } -} \ No newline at end of file +} diff --git a/events/testdata/codebuild-state-change.json b/events/testdata/codebuild-state-change.json index 2169fc8e..16ed65c8 100644 --- a/events/testdata/codebuild-state-change.json +++ b/events/testdata/codebuild-state-change.json @@ -50,7 +50,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:12:29 PM", "end-time": "Sep 1, 2017 4:12:29 PM", - "duration-in-seconds": 0.0, + "duration-in-seconds": 0, "phase-type": "SUBMITTED", "phase-status": "SUCCEEDED" }, @@ -66,7 +66,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:05 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 4.0, + "duration-in-seconds": 4, "phase-type": "DOWNLOAD_SOURCE", "phase-status": "SUCCEEDED" }, @@ -82,7 +82,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:13:10 PM", "end-time": "Sep 1, 2017 4:13:10 PM", - "duration-in-seconds": 0.0, + "duration-in-seconds": 0, "phase-type": "PRE_BUILD", "phase-status": "SUCCEEDED" }, @@ -98,7 +98,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:21 PM", - "duration-in-seconds": 0.0, + "duration-in-seconds": 0, "phase-type": "POST_BUILD", "phase-status": "SUCCEEDED" }, @@ -114,7 +114,7 @@ "phase-context": [], "start-time": "Sep 1, 2017 4:14:21 PM", "end-time": "Sep 1, 2017 4:14:26 PM", - "duration-in-seconds": 4.0, + "duration-in-seconds": 4, "phase-type": "FINALIZING", "phase-status": "SUCCEEDED" },