Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 0feb397

Browse files
committed
Add promise/callback tests
1 parent 3e5ed07 commit 0feb397

File tree

1 file changed

+63
-25
lines changed

1 file changed

+63
-25
lines changed

src/dht.js

+63-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
const expect = require('chai').expect
55

66
module.exports = (common) => {
7-
describe.only('.dht', () => {
7+
describe('.dht', () => {
88
let ipfs
9+
let peers
910

1011
before((done) => {
1112
common.setup((err, factory) => {
@@ -21,42 +22,79 @@ module.exports = (common) => {
2122
after((done) => {
2223
common.teardown(done)
2324
})
24-
xdescribe('.findpeer', () => {})
25-
describe('.get', (done) => {
26-
it('errors when getting a non-existent key from the DHT', (done) => {
27-
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
28-
expect(err).to.be.an.instanceof(Error)
29-
done()
25+
26+
describe('callback API', () => {
27+
describe('.get', (done) => {
28+
it('errors when getting a non-existent key from the DHT', (done) => {
29+
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
30+
expect(err).to.be.an.instanceof(Error)
31+
done()
32+
})
3033
})
3134
})
32-
// belongs in put or integration
33-
it('puts and gets a key value pair in the DHT', (done) => {
34-
ipfs.dht.put('scope', 'interplanetary', (err, res) => {
35-
expect(err).to.not.exist
36-
37-
expect(res).to.be.an('array')
35+
describe('.findprovs', () => {
36+
it('finds providers', (done) => {
37+
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
38+
expect(err).to.not.exist
3839

40+
expect(res).to.be.an('array')
41+
done()
42+
})
43+
})
44+
})
45+
})
46+
describe('promise API', () => {
47+
describe('.get', (done) => {
48+
it('errors when getting a non-existent key from the DHT', (done) => {
49+
ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => {
50+
expect(err).to.be.an.instanceof(Error)
51+
done()
52+
})
53+
})
54+
})
55+
describe('.findprovs', () => {
56+
it('finds providers', (done) => {
57+
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((res) => {
58+
expect(res).to.be.an('array')
59+
done()
60+
}).catch(done)
61+
})
62+
})
63+
})
64+
// Tests below are tests that haven't been implemented yet or is not
65+
// passing currently
66+
xdescribe('.findpeer', () => {
67+
it('finds other peers', (done) => {
68+
peers.a.ipfs.dht.findpeer(peers.b.peerID, (err, foundPeer) => {
69+
expect(err).to.be.empty
70+
expect(foundPeer.peerID).to.be.equal(peers.b.peerID)
71+
done()
72+
})
73+
})
74+
it('fails to find other peer, if peer doesnt exists', (done) => {
75+
peers.a.ipfs.dht.findpeer('ARandomPeerID', (err, foundPeer) => {
76+
expect(err).to.be.instanceof(Error)
77+
expect(foundPeer).to.be.equal(null)
3978
done()
40-
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
41-
// apiClients.a.dht.get('scope', (err, value) => {
42-
// expect(err).to.not.exist
43-
// expect(value).to.be.equal('interplanetary')
44-
// done()
45-
// })
4679
})
4780
})
4881
})
49-
xdescribe('.put', () => {})
50-
xdescribe('.query', () => {})
51-
describe('.findprovs', () => {
52-
it('finds providers', (done) => {
53-
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
82+
xdescribe('.put & .get', () => {
83+
it('puts and gets a key value pair in the DHT', (done) => {
84+
peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => {
5485
expect(err).to.not.exist
5586

5687
expect(res).to.be.an('array')
57-
done()
88+
89+
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
90+
peers.b.ipfs.dht.get('scope', (err, value) => {
91+
expect(err).to.not.exist
92+
expect(value).to.be.equal('interplanetary')
93+
done()
94+
})
5895
})
5996
})
6097
})
98+
xdescribe('.query', () => {})
6199
})
62100
}

0 commit comments

Comments
 (0)