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

Move dht tests from js-ipfs-api to interface-ipfs-core #385

Merged
merged 3 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't delete 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)