diff --git a/src/xd/lib/storage/fs_test.go b/src/xd/lib/storage/fs_test.go deleted file mode 100644 index 5309741..0000000 --- a/src/xd/lib/storage/fs_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package storage - -import ( - "os" - "path/filepath" - "testing" - "xd/lib/common" - "xd/lib/log" - "xd/lib/metainfo" -) - -func TestFS(t *testing.T) { - log.SetLevel("debug") - tf := new(metainfo.TorrentFile) - p := filepath.Join("test", "test.rand.bin.torrent") - f, err := os.Open(p) - if err != nil { - t.Errorf("failed to open test file: %s", err) - t.Fail() - return - } - err = tf.BDecode(f) - if err != nil { - t.Errorf("failed to decode test file: %s", err) - t.Fail() - return - } - - seed := filepath.Join("test", "seed") - leech := filepath.Join("test", "leech") - - stSeed := &FsStorage{ - DataDir: filepath.Join(seed, "download"), - MetaDir: filepath.Join(seed, "meta"), - } - - err = stSeed.Init() - if err != nil { - t.Errorf("failed to init seed storage: %s", err) - t.Fail() - return - } - - stLeech := &FsStorage{ - DataDir: filepath.Join(leech, "download"), - MetaDir: filepath.Join(leech, "meta"), - } - - err = stLeech.Init() - - if err != nil { - t.Errorf("failed to init leech storage: %s", err) - t.Fail() - return - } - - var seedTorrent Torrent - - seedTorrent, err = stSeed.OpenTorrent(tf) - - if err != nil { - t.Errorf("failed to open seed torrent: %s", err) - t.Fail() - return - } - - err = seedTorrent.VerifyAll(false) - - if err != nil { - t.Errorf("failed to verify seed data: %s", err) - t.Fail() - return - } - - var leechTorrent Torrent - - leechTorrent, err = stLeech.OpenTorrent(tf) - - if err != nil { - t.Errorf("failed to open seed torrent: %s", err) - t.Fail() - return - } - - err = leechTorrent.Allocate() - if err != nil { - t.Errorf("failed to allocate leech torrent: %s", err) - t.Fail() - return - } - - err = leechTorrent.VerifyAll(true) - - if err != nil { - t.Errorf("failed to verify initial leech data: %s", err) - t.Fail() - return - } - - var req common.PieceRequest - - pCount := tf.Info.NumPieces() - req.Length = tf.Info.PieceLength - d := uint64(tf.Info.PieceLength) - (uint64(pCount)*uint64(req.Length) - tf.TotalSize()) - t.Logf("we have %d pieces, diff=%d", pCount, d) - var pc *common.PieceData - for err == nil && pCount > req.Index { - if req.Index == pCount-1 { - req.Length = uint32(d) - } - pc, err = seedTorrent.GetPiece(&req) - if err == nil { - t.Logf("put piece idx=%d begin=%d len=%d diff=%d", pc.Index, pc.Begin, len(pc.Data), req.Length-uint32(len(pc.Data))) - err = leechTorrent.PutPiece(pc) - if err == nil { - req.Index++ - } else { - t.Errorf("leech torrent put piece failed: %s", err) - } - } else { - t.Errorf("seed torrent getpiece failed: %s", err) - } - } - - if err == nil { - err = leechTorrent.VerifyAll(false) - } - - if err != nil { - t.Fail() - } -} diff --git a/src/xd/lib/storage/test/seed/download/test.rand.bin b/src/xd/lib/storage/test/seed/download/test.rand.bin deleted file mode 100644 index 6ebf1e1..0000000 Binary files a/src/xd/lib/storage/test/seed/download/test.rand.bin and /dev/null differ diff --git a/src/xd/lib/storage/test/test.rand.bin.torrent b/src/xd/lib/storage/test/test.rand.bin.torrent deleted file mode 100644 index 696bd26..0000000 --- a/src/xd/lib/storage/test/test.rand.bin.torrent +++ /dev/null @@ -1 +0,0 @@ -d8:announce18:http://localhost/a10:created by13:mktorrent 1.013:creation datei1488900559e4:infod6:lengthi1024000e4:name13:test.rand.bin12:piece lengthi262144e6:pieces80:òm©ôø‡FªÔøvÜ<§›” Õ‡0ôßn©: