forked from libp2p/js-libp2p-kad-dht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimited-peer-list.spec.js
43 lines (34 loc) · 1020 Bytes
/
limited-peer-list.spec.js
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
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const LimitedPeerList = require('../src/limited-peer-list')
const createPeerInfo = require('./utils/create-peer-info')
describe('LimitedPeerList', () => {
let peers
before(function (done) {
this.timeout(10 * 1000)
createPeerInfo(5, (err, p) => {
if (err) {
return done(err)
}
peers = p
done()
})
})
it('basics', () => {
const l = new LimitedPeerList(4)
expect(l.push(peers[0])).to.eql(true)
expect(l.push(peers[0])).to.eql(false)
expect(l.push(peers[1])).to.eql(true)
expect(l.push(peers[2])).to.eql(true)
expect(l.push(peers[3])).to.eql(true)
expect(l.push(peers[4])).to.eql(false)
expect(l).to.have.length(4)
expect(l.pop()).to.eql(peers[3])
expect(l).to.have.length(3)
expect(l.push(peers[4])).to.eql(true)
expect(l.toArray()).to.eql([peers[0], peers[1], peers[2], peers[4]])
})
})