-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.go
39 lines (31 loc) · 966 Bytes
/
testing.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
package poker
import "testing"
// StubPlayerStore implements PlayerStore for testing purposes
type StubPlayerStore struct {
Scores map[string]int
WinCalls []string
League []Player
}
// GetPlayerScore returns a score from Scores
func (s *StubPlayerStore) GetPlayerScore(name string) int {
score := s.Scores[name]
return score
}
// RecordWin will record a win to WinCalls
func (s *StubPlayerStore) RecordWin(name string) {
s.WinCalls = append(s.WinCalls, name)
}
// GetLeague returns League
func (s *StubPlayerStore) GetLeague() League {
return s.League
}
// AssertPlayerWin allows you to spy on the store's calls to RecordWin
func AssertPlayerWin(t *testing.T, store *StubPlayerStore, winner string) {
t.Helper()
if len(store.WinCalls) != 1 {
t.Fatalf("got %d calls to RecordWin want %d", len(store.WinCalls), 1)
}
if store.WinCalls[0] != winner {
t.Errorf("did not store correct winner got '%s' want '%s'", store.WinCalls[0], winner)
}
}