]> Sergey Matveev's repositories - btrtrc.git/blob - client_test.go
Move half-open tracking into per-torrent
[btrtrc.git] / client_test.go
1 package torrent
2
3 import (
4         "os"
5         "testing"
6
7         "bitbucket.org/anacrolix/go.torrent/testutil"
8         "bitbucket.org/anacrolix/go.torrent/util"
9         "github.com/anacrolix/libtorgo/bencode"
10 )
11
12 func TestClientDefault(t *testing.T) {
13         cl, err := NewClient(nil)
14         if err != nil {
15                 t.Fatal(err)
16         }
17         cl.Stop()
18 }
19
20 func TestAddTorrentNoSupportedTrackerSchemes(t *testing.T) {
21         t.SkipNow()
22 }
23
24 func TestAddTorrentNoUsableURLs(t *testing.T) {
25         t.SkipNow()
26 }
27
28 func TestAddPeersToUnknownTorrent(t *testing.T) {
29         t.SkipNow()
30 }
31
32 func TestPieceHashSize(t *testing.T) {
33         if pieceHash.Size() != 20 {
34                 t.FailNow()
35         }
36 }
37
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)
43                 return
44         }(), nil, 0)
45         if err != nil {
46                 t.Fatal(err)
47         }
48         err = tor.setMetadata(mi.Info.Info, dir, mi.Info.Bytes)
49         if err != nil {
50                 t.Fatal(err)
51         }
52         if len(tor.Pieces) != 1 {
53                 t.Fatal("wrong number of pieces")
54         }
55         p := tor.Pieces[0]
56         if len(p.PendingChunkSpecs) != 1 {
57                 t.Fatalf("should only be 1 chunk: %v", p.PendingChunkSpecs)
58         }
59         if _, ok := p.PendingChunkSpecs[chunkSpec{
60                 Length: 13,
61         }]; !ok {
62                 t.Fatal("pending chunk spec is incorrect")
63         }
64 }
65
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 {
69                 t.Fatal(err)
70         }
71         if len(m.Added) != 2 {
72                 t.FailNow()
73         }
74         if m.Added[0].Port != 0x506 {
75                 t.FailNow()
76         }
77 }