-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
76 lines (64 loc) · 1.98 KB
/
api_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
package blokus
import (
"context"
"testing"
)
type DummyService struct {
gameID GameID
}
func (d *DummyService) CreateGame(ctx context.Context, username, gamename string, boardSize int, opt *GameOptions) (GameID, error) {
return d.gameID, nil
}
func (d *DummyService) AddPlayer(ctx context.Context, id GameID, username string, opt *PlayerOptions) error {
return nil
}
func (d *DummyService) StartGame(ctx context.Context, id GameID, username string) error {
return nil
}
func (d *DummyService) PlacePiece(ctx context.Context, id GameID, pieceID int, x, y, rot int, flip bool) error {
return nil
}
func (d *DummyService) GetGameState(ctx context.Context, id GameID) error {
return nil
}
func newDummyService(id GameID) Service {
return &DummyService{gameID: id}
}
func TestCreateGameWithoutOptions(t *testing.T) {
s := newDummyService(1234)
id, err := s.CreateGame(context.Background(), "some_user", "some game", 20, nil)
if err != nil {
t.Errorf("CreateGame: got err %v, want no error", err)
}
if got, want := id, GameID(1234); got != want {
t.Errorf("CreateGame: got %v, want %v", got, want)
}
}
func TestCreateGameWithOptions(t *testing.T) {
s := newDummyService(1234)
opts := &GameOptions{
Description: "This is my game!",
}
id, err := s.CreateGame(context.Background(), "some_user", "some game", 20, opts)
if err != nil {
t.Errorf("CreateGame: got err %v, want no error", err)
}
if got, want := id, GameID(1234); got != want {
t.Errorf("CreateGame: got %v, want %v", got, want)
}
}
func TestAddPlayerWithoutOptions(t *testing.T) {
s := newDummyService(1234)
if err := s.AddPlayer(context.Background(), GameID(1234), "some_user", nil); err != nil {
t.Errorf("AddPlayer: got err %v, want no error", err)
}
}
func TestAddPlayerWithOptions(t *testing.T) {
s := newDummyService(1234)
opts := &PlayerOptions{
Color: Red,
}
if err := s.AddPlayer(context.Background(), GameID(1234), "some_user", opts); err != nil {
t.Errorf("AddPlayer: got err %v, want no error", err)
}
}