Skip to content

Commit

Permalink
Fix Precision issue with Durations (#229)
Browse files Browse the repository at this point in the history
* Fix Precision issue with Durations

* CloudWatchEvents seem to return with precision 60.0 instead of 60
* Change tests to match
* Change types to float64

* Mix ints and floats
  • Loading branch information
whithajess authored and bmoffatt committed Sep 12, 2019
1 parent 68877f4 commit e5086e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions events/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions events/testdata/codebuild-phase-change.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -120,9 +120,9 @@
]
},
"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"
}
}
}
10 changes: 5 additions & 5 deletions events/testdata/codebuild-state-change.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand Down

0 comments on commit e5086e5

Please sign in to comment.