This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move dht tests from js-ipfs-api to interface-ipfs-core (#385)
* Move dht tests from here to interface-ipfs-core * Update interface-ipfs-core version * Add back strict mode
- Loading branch information
Showing
2 changed files
with
14 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,19 @@ | ||
/* eslint-env mocha */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const test = require('interface-ipfs-core') | ||
const FactoryClient = require('../factory/factory-client') | ||
|
||
describe('.dht', () => { | ||
it('returns an error when getting a non-existent key from the DHT', | ||
(done) => { | ||
apiClients.a.dht.get('non-existent', {timeout: '100ms'}, (err, value) => { | ||
expect(err).to.be.an.instanceof(Error) | ||
done() | ||
}) | ||
}) | ||
let fc | ||
|
||
it('puts and gets a key value pair in the DHT', (done) => { | ||
apiClients.a.dht.put('scope', 'interplanetary', (err, res) => { | ||
expect(err).to.not.exist | ||
const common = { | ||
setup: function (callback) { | ||
fc = new FactoryClient() | ||
callback(null, fc) | ||
}, | ||
teardown: function (callback) { | ||
fc.dismantle(callback) | ||
} | ||
} | ||
|
||
expect(res).to.be.an('array') | ||
|
||
done() | ||
|
||
// non ipns or pk hashes fail to fetch, known bug | ||
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234 | ||
// apiClients.a.dht.get('scope', (err, value) => { | ||
// expect(err).to.not.exist | ||
// expect(value).to.be.equal('interplanetary') | ||
// done() | ||
// }) | ||
}) | ||
}) | ||
|
||
it('.dht.findprovs', (done) => { | ||
apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { | ||
expect(err).to.not.exist | ||
|
||
expect(res).to.be.an('array') | ||
done() | ||
}) | ||
}) | ||
|
||
describe('promise', () => { | ||
it('returns an error when getting a non-existent key from the DHT', () => { | ||
return apiClients.a.dht.get('non-existent', {timeout: '100ms'}) | ||
.catch((err) => { | ||
expect(err).to.be.an.instanceof(Error) | ||
}) | ||
}) | ||
|
||
it('puts a key value pair in the DHT', () => { | ||
return apiClients.a.dht.put('scope', 'interplanetary') | ||
.then((res) => { | ||
expect(res).to.be.an('array') | ||
}) | ||
}) | ||
|
||
it('.dht.findprovs', () => { | ||
return apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') | ||
.then((res) => { | ||
expect(res).to.be.an('array') | ||
}) | ||
}) | ||
}) | ||
}) | ||
test.dht(common) |