6 "github.com/anacrolix/torrent/bencode"
7 "github.com/stretchr/testify/assert"
8 "github.com/stretchr/testify/require"
11 func TestUnmarshalHTTPResponsePeerDicts(t *testing.T) {
13 require.NoError(t, bencode.Unmarshal(
15 "d2:ip7:1.2.3.47:peer id20:thisisthe20bytepeeri4:porti9999ee"+
16 "d7:peer id20:thisisthe20bytepeeri2:ip39:2001:0db8:85a3:0000:0000:8a2e:0370:73344:porti9998ee"+
18 "6:peers618:123412341234123456"+
22 require.Len(t, hr.Peers, 2)
23 assert.Equal(t, []byte("thisisthe20bytepeeri"), hr.Peers[0].ID)
24 assert.EqualValues(t, 9999, hr.Peers[0].Port)
25 assert.EqualValues(t, 9998, hr.Peers[1].Port)
26 assert.NotNil(t, hr.Peers[0].IP)
27 assert.NotNil(t, hr.Peers[1].IP)
29 assert.Len(t, hr.Peers6, 1)
30 assert.EqualValues(t, "1234123412341234", hr.Peers6[0].IP)
31 assert.EqualValues(t, 0x3536, hr.Peers6[0].Port)
34 func TestUnmarshalHttpResponseNoPeers(t *testing.T) {
36 require.NoError(t, bencode.Unmarshal(
37 []byte("d6:peers618:123412341234123456e"),
40 require.Len(t, hr.Peers, 0)
41 assert.Len(t, hr.Peers6, 1)
44 func TestUnmarshalHttpResponsePeers6NotCompact(t *testing.T) {
46 require.Error(t, bencode.Unmarshal(
47 []byte("d6:peers6lee"),