diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-09-29 03:35:57 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-09-29 03:35:57 +0400 |
commit | 3e211b2ce8451a1ecb2bf1f253812a78c4ad0143 (patch) | |
tree | d04122aaf7d99e2a4f463a6aa69a0e0840993358 /test/basic.js | |
parent | 9e2cc16341e148a27a972d7224aba1eff421e51d (diff) |
test additional torrent types for client.add
Diffstat (limited to 'test/basic.js')
-rw-r--r-- | test/basic.js | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/test/basic.js b/test/basic.js index bd332dc..e7aaca5 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,36 +1,69 @@ -var BitTorrentClient = require('../') +var WebTorrent = require('../') +var fs = require('fs') +var http = require('http') var parseTorrent = require('parse-torrent') +var portfinder = require('portfinder') var test = require('tape') -var fs = require('fs') -var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent') +var leavesPath = __dirname + '/torrents/leaves.torrent' +var leaves = fs.readFileSync(leavesPath) var leavesTorrent = parseTorrent(leaves) -test('Test supported torrentInfo types', function (t) { +function verify (t, client, torrent) { + t.equal(torrent.infoHash, leavesTorrent.infoHash) + client.destroy() +} + +test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', function (t) { t.plan(5) - function verify (client, torrent) { - t.equal(torrent.infoHash, leavesTorrent.infoHash) - client.destroy() - } + // magnet uri (utf8 string) + var client1 = new WebTorrent({ dht: false, trackers: false }) + verify(t, client1, client1.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)) + + // torrent file (buffer) + var client2 = new WebTorrent({ dht: false, trackers: false }) + verify(t, client2, client2.add(leaves)) + + // info hash (hex string) + var client3 = new WebTorrent({ dht: false, trackers: false }) + verify(t, client3, client3.add(leavesTorrent.infoHash)) - // info hash (as a hex string) - var client1 = new BitTorrentClient({ dht: false, trackers: false }) - verify(client1, client1.add(leavesTorrent.infoHash)) + // info hash (buffer) + var client4 = new WebTorrent({ dht: false, trackers: false }) + verify(t, client4, client4.add(new Buffer(leavesTorrent.infoHash, 'hex'))) - // info hash (as a Buffer) - var client2 = new BitTorrentClient({ dht: false, trackers: false }) - verify(client2, client2.add(new Buffer(leavesTorrent.infoHash, 'hex'))) + // parsed torrent (from parse-torrent) + var client5 = new WebTorrent({ dht: false, trackers: false }) + verify(t, client5, client5.add(leavesTorrent)) - // magnet uri (as a utf8 string) - var client3 = new BitTorrentClient({ dht: false, trackers: false }) - verify(client3, client3.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)) +}) + +test('client.add (http url to a torrent file (string))', function (t) { + t.plan(1) + + var server = http.createServer(function (req, res) { + res.end(leaves) + }) + + portfinder.getPort(function (err, port) { + if (err) throw err + server.listen(port, function () { + var url = 'http://127.0.0.1:' + port + var client1 = new WebTorrent({ dht: false, trackers: false }) + client1.add(url, function (torrent) { + verify(t, client1, torrent) + server.close() + }) + }) + }) +}) - // .torrent file (as a Buffer) - var client4 = new BitTorrentClient({ dht: false, trackers: false }) - verify(client4, client4.add(leaves)) +test('client.add (filesystem path to a torrent file (string))', function (t) { + t.plan(1) - // parsed torrent (as an Object) - var client5 = new BitTorrentClient({ dht: false, trackers: false }) - verify(client5, client5.add(leavesTorrent)) + var client1 = new WebTorrent({ dht: false, trackers: false }) + client1.add(leavesPath, function (torrent) { + verify(t, client1, torrent) + }) }) |