From: Matt Joiner Date: Tue, 23 Feb 2016 11:37:38 +0000 (+1100) Subject: metainfo: Ensure that nodes encode correctly X-Git-Tag: v1.0.0~850 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d67379b3cb63be098fa6da62e932f48a0f9e98d3;p=btrtrc.git metainfo: Ensure that nodes encode correctly --- diff --git a/metainfo/nodes_test.go b/metainfo/nodes_test.go index 9a76e137..585120b7 100644 --- a/metainfo/nodes_test.go +++ b/metainfo/nodes_test.go @@ -5,6 +5,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/anacrolix/torrent/bencode" ) func testFileNodesMatch(t *testing.T, file string, nodes []Node) { @@ -38,3 +40,16 @@ func TestNodesListPairsBEP5(t *testing.T) { "83.128.223.71:23865", }) } + +func testMarshalMetainfo(t *testing.T, expected string, mi MetaInfo) { + b, err := bencode.Marshal(mi) + assert.NoError(t, err) + assert.EqualValues(t, expected, string(b)) +} + +func TestMarshalMetainfoNodes(t *testing.T) { + testMarshalMetainfo(t, "d4:infod4:name0:12:piece lengthi0e6:piecesleee", MetaInfo{}) + testMarshalMetainfo(t, "d4:infod4:name0:12:piece lengthi0e6:pieceslee5:nodesl12:1.2.3.4:555514:not a hostportee", MetaInfo{ + Nodes: []Node{"1.2.3.4:5555", "not a hostport"}, + }) +}