mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-02-22 05:09:01 +00:00
test/scrape: use common.createServer
This commit is contained in:
parent
3342c20b6b
commit
4207d80f28
@ -6,7 +6,6 @@ var fs = require('fs')
|
|||||||
var get = require('simple-get')
|
var get = require('simple-get')
|
||||||
var parseTorrent = require('parse-torrent')
|
var parseTorrent = require('parse-torrent')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
var Server = require('../').Server
|
|
||||||
var test = require('tape')
|
var test = require('tape')
|
||||||
|
|
||||||
var infoHash1 = 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
|
var infoHash1 = 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
|
||||||
@ -114,22 +113,18 @@ test('udp: MULTI scrape using Client.scrape static method', function (t) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('server: multiple info_hash scrape (manual http request)', function (t) {
|
test('server: multiple info_hash scrape (manual http request)', function (t) {
|
||||||
var server = new Server({ udp: false, ws: false })
|
t.plan(13)
|
||||||
server.on('error', function (err) {
|
|
||||||
t.error(err)
|
commonTest.createServer(t, 'http', function (server, announceUrl) {
|
||||||
})
|
var scrapeUrl = announceUrl.replace('/announce', '/scrape')
|
||||||
server.on('warning', function (err) {
|
|
||||||
t.error(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
server.listen(0, function () {
|
|
||||||
var port = server.http.address().port
|
|
||||||
var scrapeUrl = 'http://127.0.0.1:' + port + '/scrape'
|
|
||||||
var url = scrapeUrl + '?' + commonLib.querystringStringify({
|
var url = scrapeUrl + '?' + commonLib.querystringStringify({
|
||||||
info_hash: [ binaryInfoHash1, binaryInfoHash2 ]
|
info_hash: [ binaryInfoHash1, binaryInfoHash2 ]
|
||||||
})
|
})
|
||||||
|
|
||||||
get.concat(url, function (err, res, data) {
|
get.concat(url, function (err, res, data) {
|
||||||
if (err) throw err
|
t.error(err)
|
||||||
|
|
||||||
t.equal(res.statusCode, 200)
|
t.equal(res.statusCode, 200)
|
||||||
|
|
||||||
data = bencode.decode(data)
|
data = bencode.decode(data)
|
||||||
@ -146,40 +141,29 @@ test('server: multiple info_hash scrape (manual http request)', function (t) {
|
|||||||
t.equal(typeof data.files[binaryInfoHash2].incomplete, 'number')
|
t.equal(typeof data.files[binaryInfoHash2].incomplete, 'number')
|
||||||
t.equal(typeof data.files[binaryInfoHash2].downloaded, 'number')
|
t.equal(typeof data.files[binaryInfoHash2].downloaded, 'number')
|
||||||
|
|
||||||
server.close(function () {
|
server.close(function () { t.pass('server closed') })
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('server: all info_hash scrape (manual http request)', function (t) {
|
test('server: all info_hash scrape (manual http request)', function (t) {
|
||||||
var server = new Server({ udp: false, ws: false })
|
t.plan(10)
|
||||||
server.on('error', function (err) {
|
commonTest.createServer(t, 'http', function (server, announceUrl) {
|
||||||
t.error(err)
|
var scrapeUrl = announceUrl.replace('/announce', '/scrape')
|
||||||
})
|
|
||||||
server.on('warning', function (err) {
|
|
||||||
t.error(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
server.listen(0, function () {
|
|
||||||
var port = server.http.address().port
|
|
||||||
var announceUrl = 'http://127.0.0.1:' + port + '/announce'
|
|
||||||
var scrapeUrl = 'http://127.0.0.1:' + port + '/scrape'
|
|
||||||
|
|
||||||
parsedBitlove.announce = [ announceUrl ]
|
parsedBitlove.announce = [ announceUrl ]
|
||||||
|
|
||||||
// announce a torrent to the tracker
|
// announce a torrent to the tracker
|
||||||
var client = new Client(peerId, port, parsedBitlove)
|
var client = new Client(peerId, 6881, parsedBitlove)
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) { t.error(err) })
|
||||||
t.error(err)
|
client.on('warning', function (err) { t.error(err) })
|
||||||
})
|
|
||||||
client.start()
|
client.start()
|
||||||
|
|
||||||
server.once('start', function () {
|
server.once('start', function () {
|
||||||
// now do a scrape of everything by omitting the info_hash param
|
// now do a scrape of everything by omitting the info_hash param
|
||||||
get.concat(scrapeUrl, function (err, res, data) {
|
get.concat(scrapeUrl, function (err, res, data) {
|
||||||
if (err) throw err
|
t.error(err)
|
||||||
|
|
||||||
t.equal(res.statusCode, 200)
|
t.equal(res.statusCode, 200)
|
||||||
data = bencode.decode(data)
|
data = bencode.decode(data)
|
||||||
@ -191,10 +175,8 @@ test('server: all info_hash scrape (manual http request)', function (t) {
|
|||||||
t.equal(typeof data.files[binaryBitlove].incomplete, 'number')
|
t.equal(typeof data.files[binaryBitlove].incomplete, 'number')
|
||||||
t.equal(typeof data.files[binaryBitlove].downloaded, 'number')
|
t.equal(typeof data.files[binaryBitlove].downloaded, 'number')
|
||||||
|
|
||||||
client.destroy()
|
client.destroy(function () { t.pass('client destroyed') })
|
||||||
server.close(function () {
|
server.close(function () { t.pass('server closed') })
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user