6 "github.com/stretchr/testify/assert"
7 "github.com/stretchr/testify/require"
9 "github.com/anacrolix/torrent/bencode"
12 func testFileNodesMatch(t *testing.T, file string, nodes []Node) {
13 mi, err := LoadFromFile(file)
14 require.NoError(t, err)
15 assert.EqualValues(t, nodes, mi.Nodes)
18 func TestNodesListStrings(t *testing.T) {
19 testFileNodesMatch(t, "testdata/trackerless.torrent", []Node{
20 "udp://tracker.openbittorrent.com:80",
21 "udp://tracker.openbittorrent.com:80",
25 func TestNodesListPairsBEP5(t *testing.T) {
26 testFileNodesMatch(t, "testdata/issue_65a.torrent", []Node{
29 "94.209.253.165:47232",
31 "195.154.162.70:55011",
34 testFileNodesMatch(t, "testdata/issue_65b.torrent", []Node{
35 "95.211.203.130:6881",
38 "101.187.175.163:19665",
40 "83.128.223.71:23865",
44 func testMarshalMetainfo(t *testing.T, expected string, mi *MetaInfo) {
45 b, err := bencode.Marshal(*mi)
46 assert.NoError(t, err)
47 assert.EqualValues(t, expected, string(b))
50 func TestMarshalMetainfoNodes(t *testing.T) {
51 testMarshalMetainfo(t, "d4:infodee", &MetaInfo{InfoBytes: []byte("de")})
52 testMarshalMetainfo(t, "d4:infod2:hi5:theree5:nodesl12:1.2.3.4:555514:not a hostportee", &MetaInfo{
53 Nodes: []Node{"1.2.3.4:5555", "not a hostport"},
54 InfoBytes: []byte("d2:hi5:theree"),
58 func TestUnmarshalBadMetainfoNodes(t *testing.T) {
60 // Should barf on the integer in the nodes list.
61 err := bencode.Unmarshal([]byte("d5:nodesl1:ai42eee"), &mi)