]> Sergey Matveev's repositories - btrtrc.git/blob - tracker/http_test.go
adding http user-agent setters and usage
[btrtrc.git] / tracker / http_test.go
1 package tracker
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/assert"
7         "github.com/stretchr/testify/require"
8
9         "github.com/anacrolix/torrent/bencode"
10 )
11
12 var defaultHTTPUserAgent = "Go-Torrent"
13
14 func TestUnmarshalHTTPResponsePeerDicts(t *testing.T) {
15         var hr httpResponse
16         require.NoError(t, bencode.Unmarshal([]byte("d5:peersl"+
17                 "d2:ip7:1.2.3.47:peer id20:thisisthe20bytepeeri4:porti9999ee"+
18                 "d7:peer id20:thisisthe20bytepeeri2:ip39:2001:0db8:85a3:0000:0000:8a2e:0370:73344:porti9998ee"+
19                 "ee"), &hr))
20         ps, err := hr.UnmarshalPeers()
21         require.NoError(t, err)
22         require.Len(t, ps, 2)
23         assert.Equal(t, []byte("thisisthe20bytepeeri"), ps[0].ID)
24         assert.EqualValues(t, 9999, ps[0].Port)
25         assert.EqualValues(t, 9998, ps[1].Port)
26         assert.NotNil(t, ps[0].IP)
27         assert.NotNil(t, ps[1].IP)
28 }