package bencode import ( "io/ioutil" "testing" "time" "dim13.org/btr/torrent" ) func TestMarshal(t *testing.T) { v := torrent.Torrent{ Announce: "test", AnnounceList: []string{"test1", "test2", "test3"}, CreationDate: time.Now(), Info: torrent.Info{ Length: 1000, Files: []torrent.File{ {Path: []string{"A"}}, {Path: []string{"B"}}, }, }, } out, err := Marshal(v) if err != nil { t.Error(err) } t.Logf("%q\n", string(out)) } func TestParseString(t *testing.T) { in := "4:testZZZ" s, l := parseString([]byte(in)) if s != "test" || l != 6 { t.Error("expected test, got", s) } } func TestParseInt(t *testing.T) { in := "i12345e999" i, l := parseInt([]byte(in)) if i != 12345 || l != 7 { t.Error("expected 12345, got", i) } } func TestUnmarshal(t *testing.T) { files := []string{ "../examples/OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent", "../examples/OpenBSD_songs_ogg-2016-03-25-0127.torrent", "../examples/debian-8.5.0-amd64-netinst.iso.torrent", } for _, file := range files { var tor torrent.Torrent body, err := ioutil.ReadFile(file) if err != nil { t.Error(err) } err = Unmarshal(body, &tor) if err != nil { t.Error(err) } t.Logf("%+v\n", tor) } }