]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Ensure that encoded and decoded forms match
authorMatt Joiner <anacrolix@gmail.com>
Tue, 2 Dec 2014 05:27:17 +0000 (23:27 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 2 Dec 2014 05:27:17 +0000 (23:27 -0600)
metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent [new file with mode: 0644]
metainfo/metainfo_test.go

diff --git a/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent b/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent
new file mode 100644 (file)
index 0000000..492908c
Binary files /dev/null and b/metainfo/_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent differ
index f3bb734bafb60e551af5c06cc83732a9323b788b..98489656bc9a8b85a9946c39acbcd7aaad018e9b 100644 (file)
@@ -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")
 }