Skip to content

Commit 6488193

Browse files
committed
[bugfix] Add matchTimeStart to test data to fix tests
1 parent 8e29de4 commit 6488193

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

internal/app/controller/engine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ type Engine struct {
1313
StageTimes map[Stage]time.Duration
1414
config ConfigGame
1515
StateHistory []State
16+
TimeProvider func() time.Time
1617
}
1718

1819
func NewEngine(config ConfigGame) (e Engine) {
1920
e.config = config
2021
e.loadStages()
2122
e.ResetGame()
23+
e.TimeProvider = func() time.Time { return time.Now() }
2224
return
2325
}
2426

@@ -35,7 +37,7 @@ func (e *Engine) Tick(delta time.Duration) {
3537
e.updateTimes(delta)
3638

3739
if e.State.MatchTimeStart.After(time.Unix(0, 0)) {
38-
e.State.MatchDuration = time.Now().Sub(e.State.MatchTimeStart)
40+
e.State.MatchDuration = e.TimeProvider().Sub(e.State.MatchTimeStart)
3941
}
4042
}
4143

@@ -227,7 +229,7 @@ func (e *Engine) updateStage(stage Stage) (cmd *EventCommand) {
227229
}
228230

229231
if stage == StageFirstHalf {
230-
e.State.MatchTimeStart = time.Now()
232+
e.State.MatchTimeStart = e.TimeProvider()
231233
}
232234

233235
if stage == StageOvertimeFirstHalfPre {

internal/app/controller/engine_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"reflect"
99
"strings"
1010
"testing"
11+
"time"
1112
)
1213

1314
type StateTransitions struct {
@@ -38,6 +39,9 @@ func processTransitionFile(t *testing.T, fileName string) {
3839
json.Unmarshal(bytes, &stateTransitions)
3940
config := DefaultConfig().Game
4041
e := NewEngine(config)
42+
e.TimeProvider = func() time.Time {
43+
return time.Unix(1, 0)
44+
}
4145
for i, s := range stateTransitions {
4246

4347
if s.Event != nil {

internal/app/controller/testdata/transition_ballplacement.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"gameTimeElapsed": 0,
88
"gameTimeLeft": 300000000000,
99
"matchDuration": 0,
10+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
1011
"teamState": {
1112
"Blue": {
1213
"name": "",
@@ -47,6 +48,7 @@
4748
"gameTimeElapsed": 0,
4849
"gameTimeLeft": 300000000000,
4950
"matchDuration": 0,
51+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
5052
"teamState": {
5153
"Blue": {
5254
"name": "",
@@ -86,6 +88,7 @@
8688
"gameTimeElapsed": 0,
8789
"gameTimeLeft": 300000000000,
8890
"matchDuration": 0,
91+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
8992
"teamState": {
9093
"Blue": {
9194
"name": "",

internal/app/controller/testdata/transition_commands.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"gameTimeElapsed": 0,
88
"gameTimeLeft": 300000000000,
99
"matchDuration": 0,
10+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
1011
"teamState": {
1112
"Blue": {
1213
"name": "",
@@ -46,6 +47,7 @@
4647
"gameTimeElapsed": 0,
4748
"gameTimeLeft": 300000000000,
4849
"matchDuration": 0,
50+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
4951
"teamState": {
5052
"Blue": {
5153
"name": "",
@@ -86,6 +88,7 @@
8688
"gameTimeElapsed": 0,
8789
"gameTimeLeft": 300000000000,
8890
"matchDuration": 0,
91+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
8992
"teamState": {
9093
"Blue": {
9194
"name": "",
@@ -125,6 +128,7 @@
125128
"gameTimeElapsed": 0,
126129
"gameTimeLeft": 300000000000,
127130
"matchDuration": 0,
131+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
128132
"teamState": {
129133
"Blue": {
130134
"name": "",
@@ -164,6 +168,7 @@
164168
"gameTimeElapsed": 0,
165169
"gameTimeLeft": 300000000000,
166170
"matchDuration": 0,
171+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
167172
"teamState": {
168173
"Blue": {
169174
"name": "",
@@ -204,6 +209,7 @@
204209
"gameTimeElapsed": 0,
205210
"gameTimeLeft": 300000000000,
206211
"matchDuration": 0,
212+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
207213
"teamState": {
208214
"Blue": {
209215
"name": "",
@@ -243,6 +249,7 @@
243249
"gameTimeElapsed": 0,
244250
"gameTimeLeft": 300000000000,
245251
"matchDuration": 0,
252+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
246253
"teamState": {
247254
"Blue": {
248255
"name": "",
@@ -283,6 +290,7 @@
283290
"gameTimeElapsed": 0,
284291
"gameTimeLeft": 300000000000,
285292
"matchDuration": 0,
293+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
286294
"teamState": {
287295
"Blue": {
288296
"name": "",

internal/app/controller/testdata/transition_penalty.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"gameTimeElapsed": 0,
88
"gameTimeLeft": 300000000000,
99
"matchDuration": 0,
10+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
1011
"teamState": {
1112
"Blue": {
1213
"name": "",
@@ -47,6 +48,7 @@
4748
"gameTimeElapsed": 0,
4849
"gameTimeLeft": 300000000000,
4950
"matchDuration": 0,
51+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
5052
"teamState": {
5153
"Blue": {
5254
"name": "",
@@ -86,6 +88,7 @@
8688
"gameTimeElapsed": 0,
8789
"gameTimeLeft": 300000000000,
8890
"matchDuration": 0,
91+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
8992
"teamState": {
9093
"Blue": {
9194
"name": "",

internal/app/controller/testdata/transition_stages.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"gameTimeElapsed": 0,
88
"gameTimeLeft": 0,
99
"matchDuration": 0,
10+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
1011
"teamState": {
1112
"Blue": {
1213
"name": "",
@@ -46,6 +47,7 @@
4647
"gameTimeElapsed": 0,
4748
"gameTimeLeft": 0,
4849
"matchDuration": 0,
50+
"matchTimeStart": "1970-01-01T01:00:00+01:00",
4951
"teamState": {
5052
"Blue": {
5153
"name": "",
@@ -85,6 +87,7 @@
8587
"gameTimeElapsed": 0,
8688
"gameTimeLeft": 300000000000,
8789
"matchDuration": 0,
90+
"matchTimeStart": "1970-01-01T01:00:01+01:00",
8891
"teamState": {
8992
"Blue": {
9093
"name": "",
@@ -124,6 +127,7 @@
124127
"gameTimeElapsed": 0,
125128
"gameTimeLeft": 300000000000,
126129
"matchDuration": 0,
130+
"matchTimeStart": "1970-01-01T01:00:01+01:00",
127131
"teamState": {
128132
"Blue": {
129133
"name": "",
@@ -163,6 +167,7 @@
163167
"gameTimeElapsed": 0,
164168
"gameTimeLeft": 300000000000,
165169
"matchDuration": 0,
170+
"matchTimeStart": "1970-01-01T01:00:01+01:00",
166171
"teamState": {
167172
"Blue": {
168173
"name": "",
@@ -202,6 +207,7 @@
202207
"gameTimeElapsed": 0,
203208
"gameTimeLeft": 0,
204209
"matchDuration": 0,
210+
"matchTimeStart": "1970-01-01T01:00:01+01:00",
205211
"teamState": {
206212
"Blue": {
207213
"name": "",
@@ -241,6 +247,7 @@
241247
"gameTimeElapsed": 0,
242248
"gameTimeLeft": 300000000000,
243249
"matchDuration": 0,
250+
"matchTimeStart": "1970-01-01T01:00:01+01:00",
244251
"teamState": {
245252
"Blue": {
246253
"name": "",

0 commit comments

Comments
 (0)