Skip to content

Commit 7b5cd6b

Browse files
committed
unify client http + udp test suites
1 parent 5037cb3 commit 7b5cd6b

File tree

2 files changed

+51
-99
lines changed

2 files changed

+51
-99
lines changed

test/client.js

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ var portfinder = require('portfinder')
55
var Server = require('../').Server
66
var test = require('tape')
77

8-
// TODO: add test where tracker doesn't support compact
9-
108
var torrent = fs.readFileSync(__dirname + '/torrents/bitlove-intro.torrent')
119
var parsedTorrent = parseTorrent(torrent)
12-
var peerId = new Buffer('01234567890123456789')
10+
var peerId1 = new Buffer('01234567890123456789')
1311
var announceUrl = ''
1412
var port = 6881
1513

16-
function createServer (t, cb) {
17-
var server = new Server({ udp: false })
14+
function createServer (t, serverType, cb) {
15+
var opts = serverType === 'http' ? { udp: false } : { http: false }
16+
var server = new Server(opts)
1817

1918
server.on('error', function (err) {
2019
t.error(err)
@@ -27,19 +26,18 @@ function createServer (t, cb) {
2726
portfinder.getPort(function (err, port) {
2827
if (err) return t.error(err)
2928

30-
announceUrl = 'http://127.0.0.1:' + port + '/announce'
29+
announceUrl = serverType + '://127.0.0.1:' + port + '/announce'
3130
parsedTorrent.announce = [ announceUrl ]
3231

3332
server.listen(port)
3433
cb(server)
3534
})
3635
}
3736

38-
test('http: client.start()', function (t) {
37+
function testClientStart (t, serverType) {
3938
t.plan(5)
40-
41-
createServer(t, function (server) {
42-
var client = new Client(peerId, port, parsedTorrent)
39+
createServer(t, serverType, function (server) {
40+
var client = new Client(peerId1, port, parsedTorrent)
4341

4442
client.on('error', function (err) {
4543
t.error(err)
@@ -68,13 +66,20 @@ test('http: client.start()', function (t) {
6866

6967
client.start()
7068
})
69+
}
70+
71+
test('http: client.start()', function (t) {
72+
testClientStart(t, 'http')
7173
})
7274

73-
test('http: client.stop()', function (t) {
74-
t.plan(4)
75+
test('udp: client.start()', function (t) {
76+
testClientStart(t, 'udp')
77+
})
7578

76-
createServer(t, function (server) {
77-
var client = new Client(peerId, port, parsedTorrent)
79+
function testClientStop (t, serverType) {
80+
t.plan(4)
81+
createServer(t, serverType, function (server) {
82+
var client = new Client(peerId1, port, parsedTorrent)
7883

7984
client.on('error', function (err) {
8085
t.error(err)
@@ -102,13 +107,20 @@ test('http: client.stop()', function (t) {
102107

103108
}, 1000)
104109
})
110+
}
111+
112+
test('http: client.stop()', function (t) {
113+
testClientStop(t, 'http')
105114
})
106115

107-
test('http: client.update()', function (t) {
108-
t.plan(4)
116+
test('udp: client.stop()', function (t) {
117+
testClientStop(t, 'udp')
118+
})
109119

110-
createServer(t, function (server) {
111-
var client = new Client(peerId, port, parsedTorrent, { interval: 5000 })
120+
function testClientUpdate (t, serverType) {
121+
t.plan(4)
122+
createServer(t, serverType, function (server) {
123+
var client = new Client(peerId1, port, parsedTorrent, { interval: 5000 })
112124

113125
client.on('error', function (err) {
114126
t.error(err)
@@ -137,13 +149,20 @@ test('http: client.update()', function (t) {
137149
})
138150
})
139151
})
152+
}
153+
154+
test('http: client.update()', function (t) {
155+
testClientUpdate(t, 'http')
140156
})
141157

142-
test('http: client.scrape()', function (t) {
143-
t.plan(5)
158+
test('udp: client.update()', function (t) {
159+
testClientUpdate(t, 'udp')
160+
})
144161

145-
createServer(t, function (server) {
146-
var client = new Client(peerId, port, parsedTorrent)
162+
function testClientScrape (t, serverType) {
163+
t.plan(5)
164+
createServer(t, serverType, function (server) {
165+
var client = new Client(peerId1, port, parsedTorrent)
147166

148167
client.on('error', function (err) {
149168
t.error(err)
@@ -166,4 +185,14 @@ test('http: client.scrape()', function (t) {
166185

167186
client.scrape()
168187
})
188+
}
189+
190+
test('http: client.scrape()', function (t) {
191+
testClientScrape(t, 'http')
192+
})
193+
194+
test('udp: client.scrape()', function (t) {
195+
testClientScrape(t, 'udp')
196+
})
197+
169198
})

test/udp-client.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)