mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
add test: tracker client from magnet uri
This commit is contained in:
parent
3318ef642d
commit
6f565ed6fa
@ -22,6 +22,7 @@
|
||||
"bn.js": "^0.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"magnet-uri": "^2.0.1",
|
||||
"parse-torrent": "^1.1.0",
|
||||
"portfinder": "^0.2.1",
|
||||
"tape": "2.x"
|
||||
|
50
test/client-magnet.js
Normal file
50
test/client-magnet.js
Normal file
@ -0,0 +1,50 @@
|
||||
var Client = require('../').Client
|
||||
var fs = require('fs')
|
||||
var magnet = require('magnet-uri')
|
||||
var test = require('tape')
|
||||
|
||||
var uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80'
|
||||
var parsedTorrent = magnet(uri)
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
var announceUrl = 'udp://tracker.openbittorrent.com:80' // TODO: shouldn't rely on an external server!
|
||||
var port = 6881
|
||||
|
||||
test('magnet + udp: client.start/update/stop()', function (t) {
|
||||
t.plan(10)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent)
|
||||
|
||||
client.on('error', function (err) {
|
||||
t.error(err)
|
||||
})
|
||||
|
||||
client.once('update', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
})
|
||||
|
||||
client.once('peer', function (addr) {
|
||||
t.pass('there is at least one peer') // TODO: this shouldn't rely on an external server!
|
||||
|
||||
client.once('update', function (data) {
|
||||
// receive one final update after calling stop
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
|
||||
client.once('update', function (data) {
|
||||
// received an update!
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
})
|
||||
|
||||
client.stop()
|
||||
})
|
||||
|
||||
client.update()
|
||||
})
|
||||
|
||||
client.start()
|
||||
})
|
@ -3,13 +3,15 @@ var fs = require('fs')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var test = require('tape')
|
||||
|
||||
// TODO: add test where tracker doesn't support compact
|
||||
|
||||
var torrent = fs.readFileSync(__dirname + '/torrents/bitlove-intro.torrent')
|
||||
var parsedTorrent = parseTorrent(torrent)
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
var announceUrl = 'http://t.bitlove.org/announce' // TODO: shouldn't rely on an external server!
|
||||
var port = 6881
|
||||
|
||||
test('client.start()', function (t) {
|
||||
test('torrent: client.start()', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent)
|
||||
@ -32,7 +34,7 @@ test('client.start()', function (t) {
|
||||
client.start()
|
||||
})
|
||||
|
||||
test('client.stop()', function (t) {
|
||||
test('torrent: client.stop()', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent)
|
||||
@ -59,7 +61,7 @@ test('client.stop()', function (t) {
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
test('client.update()', function (t) {
|
||||
test('torrent: client.update()', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent, { interval: 5000 })
|
||||
@ -83,7 +85,7 @@ test('client.update()', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('client.scrape()', function (t) {
|
||||
test('torrent: client.scrape()', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent)
|
||||
@ -101,5 +103,3 @@ test('client.scrape()', function (t) {
|
||||
|
||||
client.scrape()
|
||||
})
|
||||
|
||||
// TODO: add test where tracker doesn't support compact
|
||||
|
@ -43,7 +43,7 @@ test('udp: client.start/update/stop()', function (t) {
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
})
|
||||
|
||||
|
||||
client.stop()
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user