diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-08-22 15:46:16 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-08-22 15:46:16 +0300 |
commit | 958f30a0341ca323c7cef794b00fe38eed845297 (patch) | |
tree | e8a0248aa350c7d3638365b771f0975027c8ae21 /test | |
parent | 89645ebe81cf46d61e4d7be423cb8c7a32283b2b (diff) |
BREAKING: Use abstract-chunk-store for storage
Part of an effort to share more code with `torrent-stream` by
@mafintosh:
https://github.com/mafintosh/torrent-stream/pull/133
https://github.com/mafintosh/torrent-stream/pull/132
Storage is now based on:
https://www.npmjs.com/package/fs-chunk-store (in node)
https://www.npmjs.com/package/memory-chunk-store (in the browser)
and:
https://www.npmjs.com/package/immediate-chunk-store
https://www.npmjs.com/package/torrent-piece
This is a BREAKING change, since users who pass in custom storage
engine with `opts.storage` will need to update their storage backend to
be `abstract-chunk-store` compliant:
https://www.npmjs.com/package/abstract-chunk-store
There are also likely other miscellaneous BREAKING API changes, since
this was a huge refactor of the codebase.
Diffstat (limited to 'test')
-rw-r--r-- | test/download-dht-magnet.js | 2 | ||||
-rw-r--r-- | test/download-dht-torrent.js | 2 | ||||
-rw-r--r-- | test/download-tracker-magnet.js | 2 | ||||
-rw-r--r-- | test/download-tracker-torrent.js | 2 | ||||
-rw-r--r-- | test/server.js | 2 | ||||
-rw-r--r-- | test/storage.js | 61 |
6 files changed, 5 insertions, 66 deletions
diff --git a/test/download-dht-magnet.js b/test/download-dht-magnet.js index 3c05b30..93e9534 100644 --- a/test/download-dht-magnet.js +++ b/test/download-dht-magnet.js @@ -55,7 +55,7 @@ test('Download using DHT (via magnet uri)', function (t) { maybeDone() }) - torrent.storage.load(fs.createReadStream(leavesPath), function (err) { + torrent.load(fs.createReadStream(leavesPath), function (err) { t.error(err) wroteStorage = true maybeDone() diff --git a/test/download-dht-torrent.js b/test/download-dht-torrent.js index 63f90bd..cda235a 100644 --- a/test/download-dht-torrent.js +++ b/test/download-dht-torrent.js @@ -55,7 +55,7 @@ test('Download using DHT (via .torrent file)', function (t) { maybeDone(null) }) - torrent.storage.load(fs.createReadStream(leavesPath), function (err) { + torrent.load(fs.createReadStream(leavesPath), function (err) { wroteStorage = true maybeDone(err) }) diff --git a/test/download-tracker-magnet.js b/test/download-tracker-magnet.js index 079c162..43ed393 100644 --- a/test/download-tracker-magnet.js +++ b/test/download-tracker-magnet.js @@ -66,7 +66,7 @@ function magnetDownloadTest (t, serverType) { t.deepEqual(torrent.files.map(function (file) { return file.name }), names) - torrent.storage.load(fs.createReadStream(leavesPath), function (err) { + torrent.load(fs.createReadStream(leavesPath), function (err) { cb(err, client1) }) }) diff --git a/test/download-tracker-torrent.js b/test/download-tracker-torrent.js index 3c9a8be..c724f0a 100644 --- a/test/download-tracker-torrent.js +++ b/test/download-tracker-torrent.js @@ -66,7 +66,7 @@ function torrentDownloadTest (t, serverType) { t.deepEqual(torrent.files.map(function (file) { return file.name }), names) - torrent.storage.load(fs.createReadStream(leavesPath), function (err) { + torrent.load(fs.createReadStream(leavesPath), function (err) { cb(err, client1) }) }) diff --git a/test/server.js b/test/server.js index 920637a..3a3cd36 100644 --- a/test/server.js +++ b/test/server.js @@ -29,6 +29,6 @@ test('start http server programmatically', function (t) { }) }) torrent.on('ready', function () { - torrent.storage.load(fs.createReadStream(leavesPath)) + torrent.load(fs.createReadStream(leavesPath)) }) }) diff --git a/test/storage.js b/test/storage.js deleted file mode 100644 index 15c3987..0000000 --- a/test/storage.js +++ /dev/null @@ -1,61 +0,0 @@ -var fs = require('fs') -var parseTorrent = require('parse-torrent') -var Storage = require('../lib/storage') -var test = require('tape') - -var torrents = [ 'leaves', 'pride' ].map(function (name) { - var torrent = fs.readFileSync(__dirname + '/torrents/' + name + '.torrent') - - return { - name: name, - torrent: torrent, - parsedTorrent: parseTorrent(torrent) - } -}) - -torrents.forEach(function (torrent) { - test('sanity check backing storage for ' + torrent.name + ' torrent', function (t) { - var parsedTorrent = torrent.parsedTorrent - var storage = new Storage(parsedTorrent) - - t.equal(storage.files.length, parsedTorrent.files.length) - t.equal(storage.pieces.length, parsedTorrent.pieces.length) - - var length = 0 - var pieces = 0 - - storage.pieces.forEach(function (piece) { - t.notOk(piece.verified) - length += piece.length - - // ensure all blocks start out empty - for (var i = 0; i < piece.blocks.length; ++i) { - t.equal(piece.blocks[i], 0) - } - }) - - t.equal(length, parsedTorrent.length) - length = 0 - - storage.files.forEach(function (file) { - t.notOk(file.done) - length += file.length - pieces += file.pieces.length - - t.assert(file.length >= 0) - t.assert(file.pieces.length >= 0) - }) - - t.equal(length, parsedTorrent.length) - - if (parsedTorrent.files.length > 1) { - // if the torrent contains multiple files, the pieces may overlap file boundaries, - // so the aggregate number of file pieces will be at least the number of pieces. - t.assert(pieces >= parsedTorrent.pieces.length) - } else { - t.equal(pieces, parsedTorrent.pieces.length) - } - - t.end() - }) -}) |