|
1 | 1 | /* eslint-env mocha */ |
2 | | -/* globals apiClients */ |
3 | 2 | 'use strict' |
4 | 3 |
|
5 | | -const expect = require('chai').expect |
| 4 | +const test = require('interface-ipfs-core') |
| 5 | +const FactoryClient = require('../factory/factory-client') |
6 | 6 |
|
7 | | -describe('.dht', () => { |
8 | | - it('returns an error when getting a non-existent key from the DHT', |
9 | | - (done) => { |
10 | | - apiClients.a.dht.get('non-existent', {timeout: '100ms'}, (err, value) => { |
11 | | - expect(err).to.be.an.instanceof(Error) |
12 | | - done() |
13 | | - }) |
14 | | - }) |
| 7 | +let fc |
15 | 8 |
|
16 | | - it('puts and gets a key value pair in the DHT', (done) => { |
17 | | - apiClients.a.dht.put('scope', 'interplanetary', (err, res) => { |
18 | | - expect(err).to.not.exist |
| 9 | +const common = { |
| 10 | + setup: function (callback) { |
| 11 | + fc = new FactoryClient() |
| 12 | + callback(null, fc) |
| 13 | + }, |
| 14 | + teardown: function (callback) { |
| 15 | + fc.dismantle(callback) |
| 16 | + } |
| 17 | +} |
19 | 18 |
|
20 | | - expect(res).to.be.an('array') |
21 | | - |
22 | | - done() |
23 | | - |
24 | | - // non ipns or pk hashes fail to fetch, known bug |
25 | | - // bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234 |
26 | | - // apiClients.a.dht.get('scope', (err, value) => { |
27 | | - // expect(err).to.not.exist |
28 | | - // expect(value).to.be.equal('interplanetary') |
29 | | - // done() |
30 | | - // }) |
31 | | - }) |
32 | | - }) |
33 | | - |
34 | | - it('.dht.findprovs', (done) => { |
35 | | - apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { |
36 | | - expect(err).to.not.exist |
37 | | - |
38 | | - expect(res).to.be.an('array') |
39 | | - done() |
40 | | - }) |
41 | | - }) |
42 | | - |
43 | | - describe('promise', () => { |
44 | | - it('returns an error when getting a non-existent key from the DHT', () => { |
45 | | - return apiClients.a.dht.get('non-existent', {timeout: '100ms'}) |
46 | | - .catch((err) => { |
47 | | - expect(err).to.be.an.instanceof(Error) |
48 | | - }) |
49 | | - }) |
50 | | - |
51 | | - it('puts a key value pair in the DHT', () => { |
52 | | - return apiClients.a.dht.put('scope', 'interplanetary') |
53 | | - .then((res) => { |
54 | | - expect(res).to.be.an('array') |
55 | | - }) |
56 | | - }) |
57 | | - |
58 | | - it('.dht.findprovs', () => { |
59 | | - return apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') |
60 | | - .then((res) => { |
61 | | - expect(res).to.be.an('array') |
62 | | - }) |
63 | | - }) |
64 | | - }) |
65 | | -}) |
| 19 | +test.dht(common) |
0 commit comments