-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgobconn_test.go
48 lines (39 loc) · 1.25 KB
/
gobconn_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
package game_test
import (
"bytes"
"github.com/ghthor/aodd/game"
"github.com/ghthor/filu/rpg2d"
"github.com/ghthor/filu/rpg2d/entity"
"github.com/ghthor/gospec"
. "github.com/ghthor/gospec"
)
func DescribeGobConn(c gospec.Context) {
c.Specify("a gob conn", func() {
buf := bytes.NewBuffer(make([]byte, 0, 1024))
gobconn := game.NewGobConn(buf)
c.Specify("can send", func() {
c.Specify("world states w/ entities", func() {
worldState := rpg2d.WorldState{
Entities: entity.StateSlice{
game.ActorEntityState{Id: 2},
game.SayEntityState{Id: 3},
game.AssailEntityState{Id: 4},
},
}
c.Expect(gobconn.EncodeAndSend(game.ET_WORLD_STATE, worldState), IsNil)
eType, err := gobconn.ReadNextType()
c.Assume(err, IsNil)
c.Expect(eType, Equals, game.ET_WORLD_STATE)
c.Specify("and can recv", func() {
var decodedState rpg2d.WorldState
c.Expect(gobconn.Decode(&decodedState), IsNil)
c.Expect(decodedState.Entities[0], Equals, game.ActorEntityState{Id: 2})
c.Expect(decodedState.Entities[1], Equals, game.SayEntityState{Id: 3})
c.Expect(decodedState.Entities[2], Equals, game.AssailEntityState{Id: 4})
})
})
c.Specify("world state diffs w/ entities", func() {
})
})
})
}