-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhud_test.go
65 lines (56 loc) · 1.5 KB
/
hud_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
package hud
import (
"testing"
"time"
"github.com/oysterriveroverdrive/hud/bluealliance/model"
"github.com/stretchr/testify/assert"
)
type testClock struct {
now time.Time
}
func (c *testClock) Now() time.Time {
newYork, _ := time.LoadLocation("America/New_York")
return c.now.In(newYork)
}
func genMatches() []*model.MatchSimple {
matches := []*model.MatchSimple{}
match := &model.MatchSimple{}
match.Alliances.Red.TeamKeys = []string{"frc8410"}
match.PredictedTime = 4444
matches = append(matches, match)
return matches
}
func TestNextMatch(t *testing.T) {
matches := genMatches()
next, err := NextMatch(matches, 8410)
assert.NoError(t, err, "should have been able to find a match")
assert.Equal(t, next.PredictedTime, int64(4444))
}
func TestPrintNextMatchSummary(t *testing.T) {
now := time.Unix(1667779200, 0)
clock := &testClock{now}
later := now.Add(10 * time.Minute)
next := &model.MatchSimple{
Alliances: struct {
Red model.MatchAlliance "json:\"red\""
Blue model.MatchAlliance "json:\"blue\""
}{
Red: model.MatchAlliance{
TeamKeys: []string{"frc8410", "frc222", "frc333"},
},
Blue: model.MatchAlliance{
TeamKeys: []string{"frc444", "frc555", "frc666"},
},
},
PredictedTime: later.Unix(),
}
got := PrintNextMatchSummary(clock, next, 8410)
want := []string{
"Match Starts At: 2022-11-07 00:10:00 +0000 UTC",
"Starts In: 10m0s",
"Alliance: Red",
"Allies: frc8410 frc222 frc333",
"Opponents: frc444 frc555 frc666",
}
assert.Equal(t, want, got)
}