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 here to interface-ipfs-core
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb committed Sep 17, 2016
1 parent 4e7b8e4 commit 33fa303
Showing 1 changed file with 13 additions and 60 deletions.
73 changes: 13 additions & 60 deletions test/interface-ipfs-core/dht.spec.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,18 @@
/* 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 33fa303

Please sign in to comment.