7 "bitbucket.org/anacrolix/go.torrent/testutil"
8 "bitbucket.org/anacrolix/go.torrent/util"
9 "github.com/anacrolix/libtorgo/bencode"
12 func TestClientDefault(t *testing.T) {
13 cl, err := NewClient(nil)
20 func TestAddTorrentNoSupportedTrackerSchemes(t *testing.T) {
24 func TestAddTorrentNoUsableURLs(t *testing.T) {
28 func TestAddPeersToUnknownTorrent(t *testing.T) {
32 func TestPieceHashSize(t *testing.T) {
33 if pieceHash.Size() != 20 {
38 func TestTorrentInitialState(t *testing.T) {
39 dir, mi := testutil.GreetingTestTorrent()
40 defer os.RemoveAll(dir)
41 tor, err := newTorrent(func() (ih InfoHash) {
42 util.CopyExact(ih[:], mi.Info.Hash)
48 err = tor.setMetadata(mi.Info.Info, dir, mi.Info.Bytes)
52 if len(tor.Pieces) != 1 {
53 t.Fatal("wrong number of pieces")
56 if len(p.PendingChunkSpecs) != 1 {
57 t.Fatalf("should only be 1 chunk: %v", p.PendingChunkSpecs)
59 if _, ok := p.PendingChunkSpecs[chunkSpec{
62 t.Fatal("pending chunk spec is incorrect")
66 func TestUnmarshalPEXMsg(t *testing.T) {
67 var m peerExchangeMessage
68 if err := bencode.Unmarshal([]byte("d5:added12:\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0ce"), &m); err != nil {
71 if len(m.Added) != 2 {
74 if m.Added[0].Port != 0x506 {