Пример #1
0
func TestParsePacket(t *testing.T) {
	login := LoginPacket{"hello", "world"}
	str := `{"Username":"******","Token": "world"}`
	b := append([]byte{0}, str...)
	parsedLogin, _ := parsePacket(b)
	unittest.CheckDeepEqual(t, Packet(&login), *parsedLogin)
}
Пример #2
0
func TestPlayerSaveLoad(t *testing.T) {
	p := MakePlayer(1, "test-player", vector.Vector2{-1, 1})
	p.Token = "waffle"
	defer func() {
		os.Remove("testpath")
	}()
	err := fileSystem.Save("testpath", p)
	unittest.CheckNil(t, &err)
	p2, err := fileSystem.LoadPlayer("testpath")
	unittest.CheckNil(t, &err)
	unittest.CheckDeepEqual(t, *p, *p2)
}
Пример #3
0
func TestChunkSerialization(t *testing.T) {
	serial := initChunk.MarshalGame()
	f, err := os.Create("chunk.json")
	unittest.CheckNil(t, &err)
	defer func() {
		os.Remove("chunk.json")
	}()
	fmt.Fprintf(f, "%s", serial)
	f.Close()

	f2, err2 := os.Open("chunk.json")
	defer f2.Close()
	f2Stats, _ := f2.Stat()
	bytes := make([]byte, f2Stats.Size())
	f2.Read(bytes)
	unittest.CheckNil(t, &err2)
	newChunk := &GameChunk{}
	serr := newChunk.UnmarshalGame(bytes)
	unittest.CheckNil(t, &serr)

	unittest.CheckDeepEqual(t, *newChunk, *initChunk)
}