From: Matt Joiner Date: Tue, 2 Dec 2014 05:27:17 +0000 (-0600) Subject: Ensure that encoded and decoded forms match X-Git-Tag: v1.0.0~1199^2~7 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=256d2e6530508d6972140124cd854a01ff595a0f;p=btrtrc.git Ensure that encoded and decoded forms match --- diff --git a/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent b/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent new file mode 100644 index 00000000..492908ca Binary files /dev/null and b/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent differ diff --git a/metainfo/metainfo_test.go b/metainfo/metainfo_test.go index f3bb734b..98489656 100644 --- a/metainfo/metainfo_test.go +++ b/metainfo/metainfo_test.go @@ -1,7 +1,12 @@ package metainfo -import "testing" -import "path" +import ( + "bytes" + "path" + "testing" + + "github.com/anacrolix/libtorgo/bencode" +) func test_file(t *testing.T, filename string) { mi, err := LoadFromFile(filename) @@ -27,9 +32,15 @@ func test_file(t *testing.T, filename string) { // t.Logf("URL: %s\n", url) // } + b, err := bencode.Marshal(mi.Info) + if !bytes.Equal(b, mi.Info.Bytes) { + t.Logf("\n%q\n%q", b[len(b)-20:], mi.Info.Bytes[len(mi.Info.Bytes)-20:]) + t.Fatal("encoded and decoded bytes don't match") + } } func TestFile(t *testing.T) { test_file(t, "_testdata/archlinux-2011.08.19-netinstall-i686.iso.torrent") test_file(t, "_testdata/continuum.torrent") + test_file(t, "_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent") }