From d67379b3cb63be098fa6da62e932f48a0f9e98d3 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 23 Feb 2016 22:37:38 +1100 Subject: [PATCH] metainfo: Ensure that nodes encode correctly --- metainfo/nodes_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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"}, + }) +} -- 2.48.1