forked from colinjfw/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_test.go
53 lines (43 loc) · 1.16 KB
/
move_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
package rules
import (
"testing"
"time"
"github.com/battlesnakeio/engine/controller/pb"
"github.com/stretchr/testify/require"
)
func TestGatherSnakeMoves(t *testing.T) {
updates := make(chan *SnakeUpdate)
gatherMoveResponses(t, "{\"move\":\"up\"}", updates)
select {
case update := <-updates:
require.NoError(t, update.Err)
require.Equal(t, "up", update.Move)
case <-time.After(250 * time.Millisecond):
require.Fail(t, "No update received over updates channel")
}
}
func TestGatherSnakeMovesBadJSON(t *testing.T) {
updates := make(chan *SnakeUpdate)
gatherMoveResponses(t, "{{", updates)
select {
case update := <-updates:
require.Error(t, update.Err)
case <-time.After(250 * time.Millisecond):
require.Fail(t, "No update received over updates channel")
}
}
func gatherMoveResponses(t *testing.T, json string, updates chan<- *SnakeUpdate) {
createClient = singleEndpointMockClient(t, "http://not.a.snake.com/move", json, 200)
go func() {
u := GatherSnakeMoves(1*time.Second, &pb.Game{}, &pb.GameFrame{
Snakes: []*pb.Snake{
&pb.Snake{
URL: "http://not.a.snake.com",
},
},
})
if len(u) > 0 {
updates <- u[0]
}
}()
}