add more thorough server tests

This commit is contained in:
Feross Aboukhadijeh 2014-04-18 23:00:40 -07:00
parent c61009eceb
commit 60b7f8dd09

View File

@ -3,12 +3,12 @@ var portfinder = require('portfinder')
var Server = require('../').Server
var test = require('tape')
var peerId = new Buffer('12345678901234567890')
var infoHash = new Buffer('4cb67059ed6bd08362da625b3ae77f6f4a075705', 'hex')
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
var peerId = '12345678901234567890'
var torrentLength = 50000
test('server', function (t) {
t.plan(12)
t.plan(17)
var server = new Server() // { interval: 50000, compactOnly: false }
@ -27,12 +27,6 @@ test('server', function (t) {
t.pass('server listening')
})
// server.torrents //
// server.torrents[infoHash] //
// server.torrents[infoHash].complete //
// server.torrents[infoHash].incomplete //
// server.torrents[infoHash].peers //
portfinder.getPort(function (err, port) {
t.error(err, 'found free port')
server.listen(port)
@ -52,6 +46,16 @@ test('server', function (t) {
t.equal(data.complete, 0)
t.equal(data.incomplete, 1)
t.equal(Object.keys(server.torrents).length, 1)
t.equal(server.torrents[infoHash].complete, 0)
t.equal(server.torrents[infoHash].incomplete, 1)
t.equal(Object.keys(server.torrents[infoHash].peers).length, 1)
t.deepEqual(server.torrents[infoHash].peers['127.0.0.1:6881'], {
ip: '127.0.0.1',
port: 6881,
peerId: peerId
})
client.complete()
client.once('update', function (data) {