Skip to content

Commit 433c8a7

Browse files
committed
[bugfix] Resolve golangci-lint issues and hidden bugs in test
1 parent 978d781 commit 433c8a7

File tree

14 files changed

+100
-59
lines changed

14 files changed

+100
-59
lines changed

cmd/ssl-ref-client/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func main() {
2626
log.Fatal(err)
2727
}
2828

29-
conn.SetReadBuffer(maxDatagramSize)
29+
if err := conn.SetReadBuffer(maxDatagramSize); err != nil {
30+
log.Printf("Could not set read buffer to %v.", maxDatagramSize)
31+
}
3032
log.Println("Receiving from", *refereeAddress)
3133

3234
b := make([]byte, maxDatagramSize)
@@ -41,7 +43,10 @@ func main() {
4143
log.Fatal("Buffer size too small")
4244
}
4345
refMsg := refproto.Referee{}
44-
proto.Unmarshal(b[0:n], &refMsg)
46+
if err := proto.Unmarshal(b[0:n], &refMsg); err != nil {
47+
log.Println("Could not unmarshal referee message")
48+
continue
49+
}
4550

4651
b, err := json.Marshal(refMsg)
4752
if err != nil {

internal/app/controller/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func LoadConfig(fileName string) (config Config, err error) {
4545
}
4646

4747
b, err := readAll(f)
48+
if err != nil {
49+
return
50+
}
4851

4952
err = yaml.Unmarshal(b, &config)
5053
if err != nil {

internal/app/controller/controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewGameController() (r *GameController) {
3434
}
3535

3636
// Run the GameController by starting an endless loop in the background
37-
func (c *GameController) Run() (err error) {
37+
func (c *GameController) Run() {
3838

3939
if err := c.historyPreserver.Open(); err != nil {
4040
log.Print("Could not open history", err)
@@ -61,7 +61,6 @@ func (c *GameController) Run() (err error) {
6161
c.publish()
6262
}
6363
}()
64-
return nil
6564
}
6665

6766
func (c *GameController) OnNewEvent(event Event) {

internal/app/controller/engine.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ func (e *Engine) updateStage(stage Stage) {
322322
}
323323

324324
e.State.Stage = stage
325-
return
326325
}
327326

328327
func (e *Engine) updatePreStages() {

internal/app/controller/engine_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,24 @@ func processTransitionFile(t *testing.T, fileName string) {
3636
t.Fatal(err)
3737
}
3838
stateTransitions := make([]StateTransitions, 0)
39-
json.Unmarshal(bytes, &stateTransitions)
39+
if err := json.Unmarshal(bytes, &stateTransitions); err != nil {
40+
t.Fatal("Could not unmarshal state transitions:", err)
41+
}
4042
config := DefaultConfig().Game
4143
e := NewEngine(config)
4244
e.TimeProvider = func() time.Time {
43-
return time.Unix(1, 0)
45+
ts, err := time.Parse("2006-01-02T15:04:05Z", "2006-01-02T15:04:05Z")
46+
if err != nil {
47+
t.Fatal("Could not parse time")
48+
}
49+
return ts
4450
}
4551
for i, s := range stateTransitions {
4652

4753
if s.Event != nil {
48-
e.Process(*s.Event)
54+
if err := e.Process(*s.Event); err != nil {
55+
t.Fatalf("Could not process event: %v", *s.Event)
56+
}
4957

5058
if s.State != nil && !reflect.DeepEqual(*e.State, *s.State) {
5159
t.Errorf("Step %v of %v failed.\nExpected: %v\n got: %v", i+1, fileName, *s.State, *e.State)

internal/app/controller/publisher.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func NewPublisher(address string) (publisher Publisher, err error) {
2828
return
2929
}
3030

31-
conn.SetWriteBuffer(maxDatagramSize)
31+
if err := conn.SetWriteBuffer(maxDatagramSize); err != nil {
32+
log.Printf("Could not set write buffer to %v.", maxDatagramSize)
33+
}
3234
log.Println("Publishing to", address)
3335

3436
publisher.conn = conn

internal/app/controller/publisher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Test_updateMessage(t *testing.T) {
3333
if *referee.CommandTimestamp != 0 {
3434
t.Errorf("Wrong CommandTimestamp: %v", *referee.CommandTimestamp)
3535
}
36-
if *referee.BlueTeamOnPositiveHalf != false {
36+
if *referee.BlueTeamOnPositiveHalf {
3737
t.Errorf("Wrong half: %v", *referee.BlueTeamOnPositiveHalf)
3838
}
3939
if referee.Yellow == nil {

internal/app/controller/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ type TeamInfo struct {
205205
type State struct {
206206
Stage Stage `json:"stage"`
207207
Command RefCommand `json:"command"`
208+
CommandFor Team `json:"commandForTeam"`
208209
GameEvent GameEventType `json:"gameEvent"`
209210
GameEventFor Team `json:"gameEventForTeam"`
210-
CommandFor Team `json:"commandForTeam"`
211211
StageTimeElapsed time.Duration `json:"stageTimeElapsed"`
212212
StageTimeLeft time.Duration `json:"stageTimeLeft"`
213213
MatchTimeStart time.Time `json:"matchTimeStart"`

internal/app/controller/testdata/transition_ballplacement.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"stage": "First Half",
55
"command": "stop",
66
"commandForTeam": null,
7+
"gameEvent": "none",
8+
"gameEventForTeam": "",
79
"stageTimeElapsed": 0,
810
"stageTimeLeft": 300000000000,
911
"matchDuration": 0,
10-
"matchTimeStart": 0,
12+
"matchTimeStart": "2006-01-02T15:04:05Z",
1113
"teamState": {
1214
"Blue": {
1315
"name": "",
@@ -45,10 +47,12 @@
4547
"stage": "First Half",
4648
"command": "ballPlacement",
4749
"commandForTeam": "Yellow",
50+
"gameEvent": "none",
51+
"gameEventForTeam": "",
4852
"stageTimeElapsed": 0,
4953
"stageTimeLeft": 300000000000,
5054
"matchDuration": 0,
51-
"matchTimeStart": 0,
55+
"matchTimeStart": "2006-01-02T15:04:05Z",
5256
"teamState": {
5357
"Blue": {
5458
"name": "",
@@ -85,10 +89,12 @@
8589
"stage": "First Half",
8690
"command": "stop",
8791
"commandForTeam": null,
92+
"gameEvent": "none",
93+
"gameEventForTeam": "",
8894
"stageTimeElapsed": 0,
8995
"stageTimeLeft": 300000000000,
9096
"matchDuration": 0,
91-
"matchTimeStart": 0,
97+
"matchTimeStart": "2006-01-02T15:04:05Z",
9298
"teamState": {
9399
"Blue": {
94100
"name": "",

internal/app/controller/testdata/transition_commands.json

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"stage": "First Half",
55
"command": "halt",
66
"commandForTeam": null,
7+
"gameEvent": "none",
8+
"gameEventForTeam": "",
79
"stageTimeElapsed": 0,
810
"stageTimeLeft": 300000000000,
911
"matchDuration": 0,
10-
"matchTimeStart": 0,
12+
"matchTimeStart": "2006-01-02T15:04:05Z",
1113
"teamState": {
1214
"Blue": {
1315
"name": "",
@@ -44,10 +46,12 @@
4446
"stage": "First Half",
4547
"command": "stop",
4648
"commandForTeam": null,
49+
"gameEvent": "none",
50+
"gameEventForTeam": "",
4751
"stageTimeElapsed": 0,
4852
"stageTimeLeft": 300000000000,
4953
"matchDuration": 0,
50-
"matchTimeStart": 0,
54+
"matchTimeStart": "2006-01-02T15:04:05Z",
5155
"teamState": {
5256
"Blue": {
5357
"name": "",
@@ -85,10 +89,12 @@
8589
"stage": "First Half",
8690
"command": "kickoff",
8791
"commandForTeam": "Yellow",
92+
"gameEvent": "none",
93+
"gameEventForTeam": "",
8894
"stageTimeElapsed": 0,
8995
"stageTimeLeft": 300000000000,
9096
"matchDuration": 0,
91-
"matchTimeStart": 0,
97+
"matchTimeStart": "2006-01-02T15:04:05Z",
9298
"teamState": {
9399
"Blue": {
94100
"name": "",
@@ -125,10 +131,12 @@
125131
"stage": "First Half",
126132
"command": "normalStart",
127133
"commandForTeam": null,
134+
"gameEvent": "none",
135+
"gameEventForTeam": "",
128136
"stageTimeElapsed": 0,
129137
"stageTimeLeft": 300000000000,
130138
"matchDuration": 0,
131-
"matchTimeStart": 0,
139+
"matchTimeStart": "2006-01-02T15:04:05Z",
132140
"teamState": {
133141
"Blue": {
134142
"name": "",
@@ -165,10 +173,12 @@
165173
"stage": "First Half",
166174
"command": "stop",
167175
"commandForTeam": null,
176+
"gameEvent": "none",
177+
"gameEventForTeam": "",
168178
"stageTimeElapsed": 0,
169179
"stageTimeLeft": 300000000000,
170180
"matchDuration": 0,
171-
"matchTimeStart": 0,
181+
"matchTimeStart": "2006-01-02T15:04:05Z",
172182
"teamState": {
173183
"Blue": {
174184
"name": "",
@@ -205,11 +215,13 @@
205215
"state": {
206216
"stage": "First Half",
207217
"command": "direct",
208-
"commandForTeam": null,
218+
"commandForTeam": "Blue",
219+
"gameEvent": "none",
220+
"gameEventForTeam": "",
209221
"stageTimeElapsed": 0,
210222
"stageTimeLeft": 300000000000,
211223
"matchDuration": 0,
212-
"matchTimeStart": 0,
224+
"matchTimeStart": "2006-01-02T15:04:05Z",
213225
"teamState": {
214226
"Blue": {
215227
"name": "",
@@ -246,10 +258,12 @@
246258
"stage": "First Half",
247259
"command": "stop",
248260
"commandForTeam": null,
261+
"gameEvent": "none",
262+
"gameEventForTeam": "",
249263
"stageTimeElapsed": 0,
250264
"stageTimeLeft": 300000000000,
251265
"matchDuration": 0,
252-
"matchTimeStart": 0,
266+
"matchTimeStart": "2006-01-02T15:04:05Z",
253267
"teamState": {
254268
"Blue": {
255269
"name": "",
@@ -286,11 +300,13 @@
286300
"state": {
287301
"stage": "First Half",
288302
"command": "indirect",
289-
"commandForTeam": null,
303+
"commandForTeam": "Yellow",
304+
"gameEvent": "none",
305+
"gameEventForTeam": "",
290306
"stageTimeElapsed": 0,
291307
"stageTimeLeft": 300000000000,
292308
"matchDuration": 0,
293-
"matchTimeStart": 0,
309+
"matchTimeStart": "2006-01-02T15:04:05Z",
294310
"teamState": {
295311
"Blue": {
296312
"name": "",

0 commit comments

Comments
 (0)