Skip to content

Commit e5086e5

Browse files
whithajessbmoffatt
authored andcommitted
Fix Precision issue with Durations (#229)
* 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
1 parent 68877f4 commit e5086e5

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

events/duration.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type DurationSeconds time.Duration
1010

1111
func (duration *DurationSeconds) UnmarshalJSON(data []byte) error {
12-
var seconds int64
12+
var seconds float64
1313
if err := json.Unmarshal(data, &seconds); err != nil {
1414
return err
1515
}
@@ -26,7 +26,7 @@ func (duration DurationSeconds) MarshalJSON() ([]byte, error) {
2626
type DurationMinutes time.Duration
2727

2828
func (duration *DurationMinutes) UnmarshalJSON(data []byte) error {
29-
var minutes int64
29+
var minutes float64
3030
if err := json.Unmarshal(data, &minutes); err != nil {
3131
return err
3232
}

events/testdata/codebuild-phase-change.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"type": "LINUX_CONTAINER",
2828
"environment-variables": []
2929
},
30-
"timeout-in-minutes": 60,
30+
"timeout-in-minutes": 60.0,
3131
"build-complete": true,
3232
"initiator": "MyCodeBuildDemoUser",
3333
"build-start-time": "Sep 1, 2017 4:12:29 PM",
@@ -45,7 +45,7 @@
4545
"phase-context": [],
4646
"start-time": "Sep 1, 2017 4:12:29 PM",
4747
"end-time": "Sep 1, 2017 4:12:29 PM",
48-
"duration-in-seconds": 0,
48+
"duration-in-seconds": 0.0,
4949
"phase-type": "SUBMITTED",
5050
"phase-status": "SUCCEEDED"
5151
},
@@ -61,7 +61,7 @@
6161
"phase-context": [],
6262
"start-time": "Sep 1, 2017 4:13:05 PM",
6363
"end-time": "Sep 1, 2017 4:13:10 PM",
64-
"duration-in-seconds": 4,
64+
"duration-in-seconds": 4.0,
6565
"phase-type": "DOWNLOAD_SOURCE",
6666
"phase-status": "SUCCEEDED"
6767
},
@@ -77,7 +77,7 @@
7777
"phase-context": [],
7878
"start-time": "Sep 1, 2017 4:13:10 PM",
7979
"end-time": "Sep 1, 2017 4:13:10 PM",
80-
"duration-in-seconds": 0,
80+
"duration-in-seconds": 0.0,
8181
"phase-type": "PRE_BUILD",
8282
"phase-status": "SUCCEEDED"
8383
},
@@ -93,7 +93,7 @@
9393
"phase-context": [],
9494
"start-time": "Sep 1, 2017 4:14:21 PM",
9595
"end-time": "Sep 1, 2017 4:14:21 PM",
96-
"duration-in-seconds": 0,
96+
"duration-in-seconds": 0.0,
9797
"phase-type": "POST_BUILD",
9898
"phase-status": "SUCCEEDED"
9999
},
@@ -109,7 +109,7 @@
109109
"phase-context": [],
110110
"start-time": "Sep 1, 2017 4:14:21 PM",
111111
"end-time": "Sep 1, 2017 4:14:26 PM",
112-
"duration-in-seconds": 4,
112+
"duration-in-seconds": 4.0,
113113
"phase-type": "FINALIZING",
114114
"phase-status": "SUCCEEDED"
115115
},
@@ -120,9 +120,9 @@
120120
]
121121
},
122122
"completed-phase-status": "SUCCEEDED",
123-
"completed-phase-duration-seconds": 4,
123+
"completed-phase-duration-seconds": 4.0,
124124
"version": "1",
125125
"completed-phase-start": "Sep 1, 2017 4:14:21 PM",
126126
"completed-phase-end": "Sep 1, 2017 4:14:26 PM"
127127
}
128-
}
128+
}

events/testdata/codebuild-state-change.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
}
3333
]
3434
},
35-
"timeout-in-minutes": 60,
35+
"timeout-in-minutes": 60.0,
3636
"build-complete": true,
3737
"initiator": "MyCodeBuildDemoUser",
3838
"build-start-time": "Sep 1, 2017 4:12:29 PM",
@@ -58,7 +58,7 @@
5858
"phase-context": [],
5959
"start-time": "Sep 1, 2017 4:12:29 PM",
6060
"end-time": "Sep 1, 2017 4:13:05 PM",
61-
"duration-in-seconds": 36,
61+
"duration-in-seconds": 36.0,
6262
"phase-type": "PROVISIONING",
6363
"phase-status": "SUCCEEDED"
6464
},
@@ -74,7 +74,7 @@
7474
"phase-context": [],
7575
"start-time": "Sep 1, 2017 4:13:10 PM",
7676
"end-time": "Sep 1, 2017 4:13:10 PM",
77-
"duration-in-seconds": 0,
77+
"duration-in-seconds": 0.0,
7878
"phase-type": "INSTALL",
7979
"phase-status": "SUCCEEDED"
8080
},
@@ -90,7 +90,7 @@
9090
"phase-context": [],
9191
"start-time": "Sep 1, 2017 4:13:10 PM",
9292
"end-time": "Sep 1, 2017 4:14:21 PM",
93-
"duration-in-seconds": 70,
93+
"duration-in-seconds": 70.0,
9494
"phase-type": "BUILD",
9595
"phase-status": "SUCCEEDED"
9696
},
@@ -106,7 +106,7 @@
106106
"phase-context": [],
107107
"start-time": "Sep 1, 2017 4:14:21 PM",
108108
"end-time": "Sep 1, 2017 4:14:21 PM",
109-
"duration-in-seconds": 0,
109+
"duration-in-seconds": 0.0,
110110
"phase-type": "UPLOAD_ARTIFACTS",
111111
"phase-status": "SUCCEEDED"
112112
},

0 commit comments

Comments
 (0)