forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alliance_station_display_test.go
83 lines (73 loc) · 2.56 KB
/
alliance_station_display_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"sync"
"testing"
"time"
)
func TestAllianceStationDisplay(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
recorder := getHttpResponse("/displays/alliance_station")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "Alliance Station Display - Untitled Event - Cheesy Arena")
}
func TestAllianceStationDisplayWebsocket(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
server, wsUrl := startTestServer()
defer server.Close()
conn, _, err := websocket.DefaultDialer.Dial(wsUrl+"/displays/alliance_station/websocket?displayId=1", nil)
assert.Nil(t, err)
defer conn.Close()
ws := &Websocket{conn, new(sync.Mutex)}
// Should get a few status updates right after connection.
readWebsocketType(t, ws, "setAllianceStationDisplay")
readWebsocketType(t, ws, "matchTiming")
readWebsocketType(t, ws, "matchTime")
readWebsocketType(t, ws, "setMatch")
readWebsocketType(t, ws, "realtimeScore")
// Change to a different screen.
mainArena.allianceStationDisplayScreen = "logo"
mainArena.allianceStationDisplayNotifier.Notify(nil)
readWebsocketType(t, ws, "matchTime")
readWebsocketType(t, ws, "setAllianceStationDisplay")
// Inform the server what display ID this is.
assert.Equal(t, "", mainArena.allianceStationDisplays["1"])
ws.Write("setAllianceStation", "R3")
time.Sleep(time.Millisecond * 10) // Allow some time for the command to be processed.
assert.Equal(t, "R3", mainArena.allianceStationDisplays["1"])
// Run through a match cycle.
mainArena.matchLoadTeamsNotifier.Notify(nil)
readWebsocketType(t, ws, "setMatch")
mainArena.AllianceStations["R1"].Bypass = true
mainArena.AllianceStations["R2"].Bypass = true
mainArena.AllianceStations["R3"].Bypass = true
mainArena.AllianceStations["B1"].Bypass = true
mainArena.AllianceStations["B2"].Bypass = true
mainArena.AllianceStations["B3"].Bypass = true
mainArena.StartMatch()
mainArena.Update()
messages := readWebsocketMultiple(t, ws, 2)
_, ok := messages["status"]
assert.True(t, ok)
_, ok = messages["matchTime"]
assert.True(t, ok)
mainArena.realtimeScoreNotifier.Notify(nil)
readWebsocketType(t, ws, "realtimeScore")
}