aboutsummaryrefslogtreecommitdiff
path: root/bencode/bencode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bencode/bencode_test.go')
-rw-r--r--bencode/bencode_test.go35
1 files changed, 26 insertions, 9 deletions
diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go
index 8f3c43f..41c1bff 100644
--- a/bencode/bencode_test.go
+++ b/bencode/bencode_test.go
@@ -1,8 +1,8 @@
package bencode
import (
+ "encoding/hex"
"io/ioutil"
- "path/filepath"
"testing"
"time"
@@ -45,21 +45,38 @@ func TestParseInt(t *testing.T) {
}
}
+var testCase = []struct {
+ Torrent string
+ InfoHash string
+}{
+ {
+ Torrent: "../examples/OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent",
+ InfoHash: "e840038dea1998c39614dcd28594501df02bd32d",
+ },
+ {
+ Torrent: "../examples/OpenBSD_songs_ogg-2016-03-25-0127.torrent",
+ InfoHash: "1aa5af9f6f533961a65169bdeeb801e611724d32",
+ },
+ {
+ Torrent: "../examples/debian-8.5.0-amd64-netinst.iso.torrent",
+ InfoHash: "47b9ad52c009f3bd562ffc6da40e5c55d3fb47f3",
+ },
+}
+
func TestUnmarshal(t *testing.T) {
- files, err := filepath.Glob("../examples/*.torrent")
- if err != nil {
- t.Error(err)
- }
- for _, file := range files {
+ for _, tc := range testCase {
var tor meta.Torrent
- body, err := ioutil.ReadFile(file)
+ body, err := ioutil.ReadFile(tc.Torrent)
if err != nil {
t.Error(err)
}
- err = Unmarshal(body, &tor)
+ sum, err := Unmarshal(body, &tor)
if err != nil {
t.Error(err)
}
- t.Logf("%+v\n", tor)
+ h := hex.EncodeToString(sum)
+ if h != tc.InfoHash {
+ t.Error("got", h, "expected", tc.InfoHash)
+ }
}
}