mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Added unit tests for the alliance station display.
This commit is contained in:
@@ -413,3 +413,76 @@ func TestRefereeDisplayWebsocket(t *testing.T) {
|
||||
mainArena.matchLoadTeamsNotifier.Notify(nil)
|
||||
readWebsocketType(t, ws, "reload")
|
||||
}
|
||||
|
||||
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()
|
||||
eventSettings.AllianceDisplayHotGoals = true
|
||||
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}
|
||||
|
||||
// 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, "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, 4)
|
||||
_, ok := messages["status"]
|
||||
assert.True(t, ok)
|
||||
_, ok = messages["matchTime"]
|
||||
assert.True(t, ok)
|
||||
_, ok = messages["hotGoalLight"]
|
||||
assert.True(t, ok)
|
||||
mainArena.realtimeScoreNotifier.Notify(nil)
|
||||
readWebsocketType(t, ws, "realtimeScore")
|
||||
}
|
||||
|
||||
14
lights.go
14
lights.go
@@ -102,6 +102,8 @@ func (lights *Lights) SetupConnections() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
lights.connections["red"] = nil
|
||||
}
|
||||
if len(eventSettings.BlueGoalLightsAddress) != 0 {
|
||||
conn, err := net.Dial("udp4", eventSettings.BlueGoalLightsAddress)
|
||||
@@ -109,6 +111,8 @@ func (lights *Lights) SetupConnections() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
lights.connections["blue"] = nil
|
||||
}
|
||||
lights.newConnections = true
|
||||
return nil
|
||||
@@ -216,11 +220,13 @@ func (lights *Lights) SetMode(mode string) {
|
||||
}
|
||||
|
||||
func (lights *Lights) sendLights() {
|
||||
for alliance, connections := range lights.connections {
|
||||
for alliance, connection := range lights.connections {
|
||||
if lights.newConnections || *lights.packets[alliance] != *lights.oldPackets[alliance] {
|
||||
_, err := (*connections).Write(lights.packets[alliance][:])
|
||||
if err != nil {
|
||||
log.Printf("Failed to send %s light packet.", alliance)
|
||||
if connection != nil {
|
||||
_, err := (*connection).Write(lights.packets[alliance][:])
|
||||
if err != nil {
|
||||
log.Printf("Failed to send %s light packet.", alliance)
|
||||
}
|
||||
}
|
||||
mainArena.hotGoalLightNotifier.Notify(lights.hotGoal)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user