package meta import "testing" var tors = map[string]string{ "bsd": "OpenBSD_5.9_amd64_install59.iso-2016-03-29-0449.torrent", "ogg": "OpenBSD_songs_ogg-2016-03-25-0127.torrent", "deb": "debian-8.5.0-amd64-netinst.iso.torrent", "mul": "multi.torrent", } func TestHash(t *testing.T) { tor, err := New("../testdata/" + tors["bsd"]) if err != nil { t.Error(err) } if tor.Info.Hash() != [20]byte{0xe8, 0x40, 0x03, 0x8d, 0xea, 0x19, 0x98, 0xc3, 0x96, 0x14, 0xdc, 0xd2, 0x85, 0x94, 0x50, 0x1d, 0xf0, 0x2b, 0xd3, 0x2d} { t.Errorf("wrong info hash %x", tor.Info.Hash()) } } func TestPieces(t *testing.T) { tor, err := New("../testdata/" + tors["mul"]) if err != nil { t.Error(err) } for i, p := range tor.Info.Pieces { n, off := tor.Info.findFirstFile(int64(tor.Info.PieceLength * i)) t.Log(i, n, off, p) } } func TestPieces2(t *testing.T) { tor, err := New("../testdata/" + tors["mul"]) if err != nil { t.Error(err) } for i, p := range tor.Info.Pieces { t.Logf("%d %x\n", i, p) } } func TestReadAt(t *testing.T) { t.Skip() tor, err := New("../testdata/" + tors["bsd"]) if err != nil { t.Error(err) } buf := make([]byte, tor.Info.PieceLength) n, err := tor.Info.ReadAt(buf, 0) if err != nil { t.Log(err) } if n != len(buf) { t.Error("want", len(buf), "got", n) } //t.Logf("% x\n", buf) }