Пример #1
0
func TestBytesList(t *T) {
	r := &Reply{Type: MultiReply}
	r.Elems = make([]*Reply, 3)
	r.Elems[0] = &Reply{Type: BulkReply, buf: []byte("0")}
	r.Elems[1] = &Reply{Type: NilReply}
	r.Elems[2] = &Reply{Type: BulkReply, buf: []byte("2")}
	l, err := r.ListBytes()
	assert.Nil(t, err)
	assert.Equal(t, 3, len(l))
	assert.Equal(t, []byte("0"), l[0])
	assert.Nil(t, l[1])
	assert.Equal(t, []byte("2"), l[2])
}
Пример #2
0
func TestMessageWrite(t *T) {
	var err error
	var m *Message
	buf := bytes.NewBuffer([]byte{})
	for _, test := range arbitraryTests {
		t.Logf("Checking test; %v", test)
		buf.Reset()
		m, err = NewMessage(test.expect)
		assert.Nil(t, err)
		err = WriteMessage(buf, m)
		assert.Nil(t, err)
		assert.Equal(t, test.expect, buf.Bytes())
	}
}
Пример #3
0
func TestStr(t *T) {
	r := &Reply{Type: ErrorReply, Err: LoadingError}
	_, err := r.Str()
	assert.Equal(t, LoadingError, err)

	r = &Reply{Type: IntegerReply}
	_, err = r.Str()
	assert.NotNil(t, err)

	r = &Reply{Type: StatusReply, buf: []byte("foo")}
	b, err := r.Str()
	assert.Nil(t, err)
	assert.Equal(t, "foo", b)

	r = &Reply{Type: BulkReply, buf: []byte("foo")}
	b, err = r.Str()
	assert.Nil(t, err)
	assert.Equal(t, "foo", b)
}
Пример #4
0
func TestInt64(t *T) {
	r := &Reply{Type: ErrorReply, Err: LoadingError}
	_, err := r.Int64()
	assert.Equal(t, LoadingError, err)

	r = &Reply{Type: IntegerReply, int: 5}
	b, err := r.Int64()
	assert.Nil(t, err)
	assert.Equal(t, int64(5), b)

	r = &Reply{Type: BulkReply, buf: []byte("5")}
	b, err = r.Int64()
	assert.Nil(t, err)
	assert.Equal(t, int64(5), b)

	r = &Reply{Type: BulkReply, buf: []byte("foo")}
	_, err = r.Int64()
	assert.NotNil(t, err)
}
Пример #5
0
func TestWriteArbitraryAsFlattenedStrings(t *T) {
	var err error
	buf := bytes.NewBuffer([]byte{})
	for _, test := range arbitraryAsFlattenedStringsTests {
		t.Logf("Checking test %v", test)
		buf.Reset()
		err = WriteArbitraryAsFlattenedStrings(buf, test.val)
		assert.Nil(t, err)
		assert.Equal(t, test.expect, buf.Bytes())
	}
}
Пример #6
0
func TestBool(t *T) {
	r := &Reply{Type: IntegerReply, int: 0}
	b, err := r.Bool()
	assert.Nil(t, err)
	assert.Equal(t, false, b)

	r = &Reply{Type: StatusReply, buf: []byte("0")}
	b, err = r.Bool()
	assert.Nil(t, err)
	assert.Equal(t, false, b)

	r = &Reply{Type: IntegerReply, int: 2}
	b, err = r.Bool()
	assert.Nil(t, err)
	assert.Equal(t, true, b)

	r = &Reply{Type: NilReply}
	_, err = r.Bool()
	assert.NotNil(t, err)
}
Пример #7
0
func TestLoadGame(t *testing.T) {
	StartGame(aGameId, aFirstPlayerId)

	game, error := LoadGame(aGameId)

	assert.Nil(t, error)
	assert.NotNil(t, game)
	assert.Equal(t, game.GameId, aGameId)
	assert.Equal(t, game.GamerOneId, aFirstPlayerId)
	assert.Equal(t, game.LastPlayer, false)
	assert.Equal(t, len(game.State), 7, "Table should have 7 columns")
	assert.Equal(t, len(game.State[0]), 6, "Table should have 6 columns")
}
Пример #8
0
func TestStartGame(t *testing.T) {
	game, error := StartGame(aGameId, aFirstPlayerId)

	assert.Nil(t, error)
	assert.NotNil(t, game)
	assert.Equal(t, len(game.State), 7, "Table should have 7 columns")
	assert.Equal(t, len(game.State[0]), 6, "Table should have 6 columns")

	for i := range game.State {
		for j := range game.State[i] {
			assert.Equal(t, game.State[i][j], uint8(0), "Table should be 0 initialized")
		}
	}
}
Пример #9
0
func TestHash(t *T) {
	r := &Reply{Type: MultiReply}
	r.Elems = make([]*Reply, 6)
	r.Elems[0] = &Reply{Type: BulkReply, buf: []byte("a")}
	r.Elems[1] = &Reply{Type: BulkReply, buf: []byte("0")}
	r.Elems[2] = &Reply{Type: BulkReply, buf: []byte("b")}
	r.Elems[3] = &Reply{Type: NilReply}
	r.Elems[4] = &Reply{Type: BulkReply, buf: []byte("c")}
	r.Elems[5] = &Reply{Type: BulkReply, buf: []byte("2")}
	h, err := r.Hash()
	assert.Nil(t, err)
	assert.Equal(t, "0", h["a"])
	assert.Equal(t, "", h["b"])
	assert.Equal(t, "2", h["c"])
}
Пример #10
0
func TestInt(t *T) {
	r := &Reply{Type: IntegerReply, int: 5}
	b, err := r.Int()
	assert.Nil(t, err)
	assert.Equal(t, 5, b)
}
Пример #11
0
func TestBytes(t *T) {
	r := &Reply{Type: BulkReply, buf: []byte("foo")}
	b, err := r.Bytes()
	assert.Nil(t, err)
	assert.Equal(t, []byte("foo"), b)
}
Пример #12
0
func dial(t *T) *Client {
	client, err := DialTimeout("tcp", "127.0.0.1:6379", 10*time.Second)
	assert.Nil(t, err)
	return client
}