Exemplo n.º 1
0
func TestFindingHolderWithValidID(t *testing.T) {
	d := protocol.NewDealer()
	pack := &packet.Packet{ID: 0x00}

	holder := d.GetHolderType(pack)
	assert.Equal(t, holder, reflect.TypeOf(packet.Handshake{}))
}
Exemplo n.º 2
0
func TestPacketEncoding(t *testing.T) {
	handshake := packet.Handshake{
		ProtocolVersion: 47,
		ServerAddress:   "localhdst",
		ServerPort:      25565,
		NextState:       1,
	}

	d := protocol.NewDealer()
	e, err := d.Encode(handshake)

	assert.Nil(t, err)
	assert.Equal(t, []byte{
		0x0f, 0x00, 0x2f, 0x09, 0x6c, 0x6f, 0x63, 0x61,
		0x6c, 0x68, 0x64, 0x73, 0x74, 0x63, 0xdd, 0x01,
	}, e)
}
Exemplo n.º 3
0
func TestPacketDecoding(t *testing.T) {
	d := protocol.NewDealer()
	p := &packet.Packet{
		ID: 0x00,
		Data: []byte{
			0x2f, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
			0x64, 0x73, 0x74, 0x63, 0xdd, 0x01,
		},
	}

	v, err := d.Decode(p)

	assert.Nil(t, err)
	hsk, _ := v.(packet.Handshake)

	assert.IsType(t, hsk, packet.Handshake{})

	assert.Equal(t, types.UVarint(47), hsk.ProtocolVersion)
	assert.Equal(t, types.String("localhdst"), hsk.ServerAddress)
	assert.Equal(t, types.UShort(25565), hsk.ServerPort)
	assert.Equal(t, types.UVarint(1), hsk.NextState)
}
Exemplo n.º 4
0
func TestFindingHolderWithInvalidID(t *testing.T) {
	d := protocol.NewDealer()
	pack := &packet.Packet{ID: -1}

	assert.Nil(t, d.GetHolderType(pack))
}
Exemplo n.º 5
0
func TestDecoderInitialization(t *testing.T) {
	d := protocol.NewDealer()
	assert.IsType(t, d, &protocol.Dealer{})
}