metainfo: Ensure that nodes encode correctly

This commit is contained in:
Matt Joiner 2016-02-23 22:37:38 +11:00
parent 752e884155
commit d67379b3cb
1 changed files with 15 additions and 0 deletions

View File

@ -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"},
})
}