forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
44 lines (35 loc) · 1.65 KB
/
Copy pathtest.js
File metadata and controls
44 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var assert = require('assert');
var compact2string = require('./');
describe('compact2string', function() {
it('should return expected IPv4 address', function() {
assert.equal('10.10.10.5:65408', compact2string(new Buffer("0A0A0A05FF80", "hex")));
});
it('should return expected IPv6 address', function() {
assert.equal('[2a03:2880:2110:9f07:face:b00c::1]:80', compact2string(new Buffer("2a03288021109f07faceb00c000000010050", "hex")));
});
it('should throw an error if the buffer length isn\'t 6 or 18', function() {
assert.throws(function() {
compact2string(new Buffer("0A0A0A05", "hex"));
}, /should contain 6 or 18 bytes/);
});
});
describe('compact2string.multi', function() {
it('should return expected multi', function() {
assert.deepEqual([ '10.10.10.5:128', '100.56.58.99:28525' ], compact2string.multi(new Buffer("0A0A0A05008064383a636f6d", "hex")));
});
it('should throw an error if the buffer isn\'t a multiple of 6', function() {
assert.throws(function() {
compact2string.multi(new Buffer("0A0A0A05050505", "hex"));
}, /multiple of/);
});
});
describe('compact2string.multi6', function() {
it('should return expected multi6', function() {
assert.deepEqual([ '[2a03:2880:2110:9f07:face:b00c::1]:80', '[2a00:1450:4008:801::1010]:443' ], compact2string.multi6(new Buffer("2a03288021109f07faceb00c0000000100502a00145040080801000000000000101001bb", "hex")));
});
it('should throw an error if the buffer isn\'t a multiple of 18', function() {
assert.throws(function() {
compact2string.multi6(new Buffer("0A0A0A050505050A0A0A050505050A0A0A05050505", "hex"));
}, /multiple of/);
});
});