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

Commit

Permalink
Move dht tests from js-ipfs-api to interface-ipfs-core (#385)
Browse files Browse the repository at this point in the history
* Move dht tests from here to interface-ipfs-core

* Update interface-ipfs-core version

* Add back strict mode
  • Loading branch information
victorb authored and daviddias committed Nov 9, 2016
1 parent 5ada84a commit 1487d3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 60 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"chai": "^3.5.0",
"gulp": "^3.9.1",
"hapi": "^15.2.0",
"interface-ipfs-core": "^0.18.2",
"interface-ipfs-core": "^0.18.3",
"ipfsd-ctl": "^0.17.0",
"pre-commit": "^1.1.3",
"socket.io": "^1.5.1",
Expand Down
72 changes: 13 additions & 59 deletions test/interface-ipfs-core/dht.spec.js
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)

0 comments on commit 1487d3e

Please sign in to comment.