mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 02:46:29 +00:00
test: use webtorrent-fixtures
This commit is contained in:
parent
1f4a68ae09
commit
e336f1a070
@ -52,7 +52,7 @@ var Client = require('bittorrent-tracker')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var fs = require('fs')
|
||||
|
||||
var torrent = fs.readFileSync(__dirname + '/torrents/bitlove-intro.torrent')
|
||||
var torrent = fs.readFileSync(__dirname + '/torrents/name.torrent')
|
||||
var parsedTorrent = parseTorrent(torrent) // { infoHash: 'xxx', length: xx, announce: ['xx', 'xx'] }
|
||||
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
@ -42,10 +42,10 @@
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"magnet-uri": "^5.0.0",
|
||||
"parse-torrent": "^5.0.0",
|
||||
"magnet-uri": "^5.1.3",
|
||||
"standard": "^6.0.4",
|
||||
"tape": "^4.0.0"
|
||||
"tape": "^4.0.0",
|
||||
"webtorrent-fixtures": "^1.3.0"
|
||||
},
|
||||
"keywords": [
|
||||
"bittorrent",
|
||||
|
@ -1,17 +1,16 @@
|
||||
var Client = require('../')
|
||||
var common = require('./common')
|
||||
var fs = require('fs')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var path = require('path')
|
||||
var extend = require('xtend')
|
||||
var fixtures = require('webtorrent-fixtures')
|
||||
var test = require('tape')
|
||||
|
||||
var torrent = fs.readFileSync(path.join(__dirname, 'torrents/sintel-5gb.torrent'))
|
||||
var parsedTorrent = parseTorrent(torrent)
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
||||
function testLargeTorrent (t, serverType) {
|
||||
t.plan(9)
|
||||
|
||||
var parsedTorrent = extend(fixtures.sintel.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId, 6881, parsedTorrent, { wrtc: {} })
|
||||
|
@ -1,15 +1,16 @@
|
||||
var Client = require('../')
|
||||
var common = require('./common')
|
||||
var fixtures = require('webtorrent-fixtures')
|
||||
var magnet = require('magnet-uri')
|
||||
var test = require('tape')
|
||||
|
||||
var uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub'
|
||||
var parsedTorrent = magnet(uri)
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
||||
function testMagnet (t, serverType) {
|
||||
t.plan(9)
|
||||
|
||||
var parsedTorrent = magnet(fixtures.leaves.magnetURI)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
var Client = require('../')
|
||||
var common = require('./common')
|
||||
var fs = require('fs')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var path = require('path')
|
||||
var extend = require('xtend')
|
||||
var fixtures = require('webtorrent-fixtures')
|
||||
var test = require('tape')
|
||||
|
||||
var torrent = fs.readFileSync(path.join(__dirname, 'torrents/bitlove-intro.torrent'))
|
||||
var parsedTorrent = parseTorrent(torrent)
|
||||
var peerId1 = new Buffer('01234567890123456789')
|
||||
var peerId2 = new Buffer('12345678901234567890')
|
||||
var peerId3 = new Buffer('23456789012345678901')
|
||||
@ -14,6 +11,9 @@ var port = 6881
|
||||
|
||||
function testClientStart (t, serverType) {
|
||||
t.plan(4)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
@ -54,6 +54,9 @@ test('ws: client.start()', function (t) {
|
||||
|
||||
function testClientStop (t, serverType) {
|
||||
t.plan(3)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
@ -94,6 +97,9 @@ test('ws: client.stop()', function (t) {
|
||||
|
||||
function testClientUpdate (t, serverType) {
|
||||
t.plan(4)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
@ -141,6 +147,9 @@ test('ws: client.update()', function (t) {
|
||||
|
||||
function testClientScrape (t, serverType) {
|
||||
t.plan(4)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
@ -178,6 +187,9 @@ test('udp: client.scrape()', function (t) {
|
||||
|
||||
function testClientAnnounceWithParams (t, serverType) {
|
||||
t.plan(5)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
@ -220,6 +232,9 @@ test('ws: client.announce() with params', function (t) {
|
||||
|
||||
function testClientGetAnnounceOpts (t, serverType) {
|
||||
t.plan(5)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var opts = {
|
||||
@ -268,6 +283,9 @@ test('ws: client `opts.getAnnounceOpts`', function (t) {
|
||||
|
||||
function testClientAnnounceWithNumWant (t, serverType) {
|
||||
t.plan(4)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client1 = new Client(peerId1, port, parsedTorrent, { wrtc: {} })
|
||||
|
@ -1,33 +1,29 @@
|
||||
var Client = require('../')
|
||||
var common = require('./common')
|
||||
var fs = require('fs')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var path = require('path')
|
||||
var extend = require('xtend')
|
||||
var fixtures = require('webtorrent-fixtures')
|
||||
var test = require('tape')
|
||||
|
||||
var bitlove = fs.readFileSync(path.join(__dirname, 'torrents/bitlove-intro.torrent'))
|
||||
var parsedBitlove = parseTorrent(bitlove)
|
||||
|
||||
var leaves = fs.readFileSync(path.join(__dirname, 'torrents/leaves.torrent'))
|
||||
var parsedLeaves = parseTorrent(leaves)
|
||||
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
||||
function testFilterOption (t, serverType) {
|
||||
t.plan(8)
|
||||
|
||||
var parsedAlice = extend(fixtures.alice.parsedTorrent)
|
||||
var parsedLeaves = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
var opts = { serverType: serverType } // this is test-suite-only option
|
||||
opts.filter = function (infoHash, params, cb) {
|
||||
process.nextTick(function () {
|
||||
cb(infoHash !== parsedBitlove.infoHash)
|
||||
cb(infoHash !== parsedAlice.infoHash)
|
||||
})
|
||||
}
|
||||
|
||||
common.createServer(t, opts, function (server, announceUrl) {
|
||||
parsedBitlove.announce = [ announceUrl ]
|
||||
parsedAlice.announce = [ announceUrl ]
|
||||
parsedLeaves.announce = [ announceUrl ]
|
||||
|
||||
var client = new Client(peerId, 6881, parsedBitlove, { wrtc: {} })
|
||||
var client = new Client(peerId, 6881, parsedAlice, { wrtc: {} })
|
||||
|
||||
client.on('error', function (err) { t.error(err) })
|
||||
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
||||
@ -82,25 +78,28 @@ test('ws: filter option blocks tracker from tracking torrent', function (t) {
|
||||
function testFilterCustomError (t, serverType) {
|
||||
t.plan(8)
|
||||
|
||||
var parsedLeaves = extend(fixtures.leaves.parsedTorrent)
|
||||
var parsedAlice = extend(fixtures.alice.parsedTorrent)
|
||||
|
||||
var opts = { serverType: serverType } // this is test-suite-only option
|
||||
opts.filter = function (infoHash, params, cb) {
|
||||
process.nextTick(function () {
|
||||
if (infoHash === parsedBitlove.infoHash) cb(new Error('bitlove blocked'))
|
||||
if (infoHash === parsedAlice.infoHash) cb(new Error('alice blocked'))
|
||||
else cb(true)
|
||||
})
|
||||
}
|
||||
|
||||
common.createServer(t, opts, function (server, announceUrl) {
|
||||
parsedBitlove.announce = [ announceUrl ]
|
||||
parsedAlice.announce = [ announceUrl ]
|
||||
parsedLeaves.announce = [ announceUrl ]
|
||||
|
||||
var client = new Client(peerId, 6881, parsedBitlove, { wrtc: {} })
|
||||
var client = new Client(peerId, 6881, parsedAlice, { wrtc: {} })
|
||||
|
||||
client.on('error', function (err) { t.error(err) })
|
||||
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
||||
|
||||
client.once('warning', function (err) {
|
||||
t.ok(/bitlove blocked/.test(err.message), 'got client warning')
|
||||
t.ok(/alice blocked/.test(err.message), 'got client warning')
|
||||
|
||||
client.destroy(function () {
|
||||
t.pass('client destroyed')
|
||||
@ -126,7 +125,7 @@ function testFilterCustomError (t, serverType) {
|
||||
|
||||
server.removeAllListeners('warning')
|
||||
server.once('warning', function (err) {
|
||||
t.ok(/bitlove blocked/.test(err.message), 'got server warning')
|
||||
t.ok(/alice blocked/.test(err.message), 'got server warning')
|
||||
t.equal(Object.keys(server.torrents).length, 0)
|
||||
})
|
||||
|
||||
|
@ -2,27 +2,19 @@ var bencode = require('bencode')
|
||||
var Client = require('../')
|
||||
var commonLib = require('../lib/common')
|
||||
var commonTest = require('./common')
|
||||
var fs = require('fs')
|
||||
var extend = require('xtend')
|
||||
var fixtures = require('webtorrent-fixtures')
|
||||
var get = require('simple-get')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var path = require('path')
|
||||
var test = require('tape')
|
||||
|
||||
var infoHash1 = 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
|
||||
var binaryInfoHash1 = commonLib.hexToBinary(infoHash1)
|
||||
var infoHash2 = 'bbb67059ed6bd08362da625b3ae77f6f4a075bbb'
|
||||
var binaryInfoHash2 = commonLib.hexToBinary(infoHash2)
|
||||
|
||||
var bitlove = fs.readFileSync(path.join(__dirname, 'torrents/bitlove-intro.torrent'))
|
||||
var parsedBitlove = parseTorrent(bitlove)
|
||||
var binaryBitlove = commonLib.hexToBinary(parsedBitlove.infoHash)
|
||||
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
||||
function testSingle (t, serverType) {
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
|
||||
commonTest.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedBitlove.announce = [ announceUrl ]
|
||||
var client = new Client(peerId, 6881, parsedBitlove)
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId, 6881, parsedTorrent)
|
||||
|
||||
client.on('error', function (err) {
|
||||
t.error(err)
|
||||
@ -36,7 +28,7 @@ function testSingle (t, serverType) {
|
||||
|
||||
client.on('scrape', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.infoHash, parsedBitlove.infoHash)
|
||||
t.equal(data.infoHash, parsedTorrent.infoHash)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
t.equal(typeof data.downloaded, 'number')
|
||||
@ -58,10 +50,10 @@ test('udp: single info_hash scrape', function (t) {
|
||||
|
||||
function clientScrapeStatic (t, serverType) {
|
||||
commonTest.createServer(t, serverType, function (server, announceUrl) {
|
||||
Client.scrape(announceUrl, infoHash1, function (err, data) {
|
||||
Client.scrape(announceUrl, fixtures.leaves.parsedTorrent.infoHash, function (err, data) {
|
||||
t.error(err)
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.infoHash, infoHash1)
|
||||
t.equal(data.infoHash, fixtures.leaves.parsedTorrent.infoHash)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
t.equal(typeof data.downloaded, 'number')
|
||||
@ -81,6 +73,9 @@ test('udp: scrape using Client.scrape static method', function (t) {
|
||||
})
|
||||
|
||||
function clientScrapeMulti (t, serverType) {
|
||||
var infoHash1 = fixtures.leaves.parsedTorrent.infoHash
|
||||
var infoHash2 = fixtures.alice.parsedTorrent.infoHash
|
||||
|
||||
commonTest.createServer(t, serverType, function (server, announceUrl) {
|
||||
Client.scrape(announceUrl, [ infoHash1, infoHash2 ], function (err, results) {
|
||||
t.error(err)
|
||||
@ -115,6 +110,9 @@ test('udp: MULTI scrape using Client.scrape static method', function (t) {
|
||||
test('server: multiple info_hash scrape (manual http request)', function (t) {
|
||||
t.plan(13)
|
||||
|
||||
var binaryInfoHash1 = commonLib.hexToBinary(fixtures.leaves.parsedTorrent.infoHash)
|
||||
var binaryInfoHash2 = commonLib.hexToBinary(fixtures.alice.parsedTorrent.infoHash)
|
||||
|
||||
commonTest.createServer(t, 'http', function (server, announceUrl) {
|
||||
var scrapeUrl = announceUrl.replace('/announce', '/scrape')
|
||||
|
||||
@ -148,13 +146,17 @@ test('server: multiple info_hash scrape (manual http request)', function (t) {
|
||||
|
||||
test('server: all info_hash scrape (manual http request)', function (t) {
|
||||
t.plan(10)
|
||||
|
||||
var parsedTorrent = extend(fixtures.leaves.parsedTorrent)
|
||||
var binaryInfoHash = commonLib.hexToBinary(parsedTorrent.infoHash)
|
||||
|
||||
commonTest.createServer(t, 'http', function (server, announceUrl) {
|
||||
var scrapeUrl = announceUrl.replace('/announce', '/scrape')
|
||||
|
||||
parsedBitlove.announce = [ announceUrl ]
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
|
||||
// announce a torrent to the tracker
|
||||
var client = new Client(peerId, 6881, parsedBitlove)
|
||||
var client = new Client(peerId, 6881, parsedTorrent)
|
||||
client.on('error', function (err) { t.error(err) })
|
||||
client.on('warning', function (err) { t.error(err) })
|
||||
|
||||
@ -170,10 +172,10 @@ test('server: all info_hash scrape (manual http request)', function (t) {
|
||||
t.ok(data.files)
|
||||
t.equal(Object.keys(data.files).length, 1)
|
||||
|
||||
t.ok(data.files[binaryBitlove])
|
||||
t.equal(typeof data.files[binaryBitlove].complete, 'number')
|
||||
t.equal(typeof data.files[binaryBitlove].incomplete, 'number')
|
||||
t.equal(typeof data.files[binaryBitlove].downloaded, 'number')
|
||||
t.ok(data.files[binaryInfoHash])
|
||||
t.equal(typeof data.files[binaryInfoHash].complete, 'number')
|
||||
t.equal(typeof data.files[binaryInfoHash].incomplete, 'number')
|
||||
t.equal(typeof data.files[binaryInfoHash].downloaded, 'number')
|
||||
|
||||
client.destroy(function () { t.pass('client destroyed') })
|
||||
server.close(function () { t.pass('server closed') })
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user