|
1 | 1 | /* eslint-env mocha */
|
2 |
| -/* globals apiClients */ |
3 |
| -'use strict' |
4 | 2 |
|
5 |
| -const expect = require('chai').expect |
| 3 | +const test = require('interface-ipfs-core') |
| 4 | +const FactoryClient = require('../factory/factory-client') |
6 | 5 |
|
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 |
| - }) |
| 6 | +let fc |
15 | 7 |
|
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 |
| 8 | +const common = { |
| 9 | + setup: function (callback) { |
| 10 | + fc = new FactoryClient() |
| 11 | + callback(null, fc) |
| 12 | + }, |
| 13 | + teardown: function (callback) { |
| 14 | + fc.dismantle(callback) |
| 15 | + } |
| 16 | +} |
19 | 17 |
|
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 |
| -}) |
| 18 | +test.dht(common) |
0 commit comments