From 1487d3e5da2446d05ccea19c6cb039ebcf9c47d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=A0=C9=AA=E1=B4=84=E1=B4=9B=E1=B4=8F=CA=80=20=CA=99?= =?UTF-8?q?=E1=B4=8A=E1=B4=87=CA=9F=E1=B4=8B=CA=9C=E1=B4=8F=CA=9F=E1=B4=8D?= Date: Wed, 9 Nov 2016 13:36:29 +0100 Subject: [PATCH] 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 --- package.json | 2 +- test/interface-ipfs-core/dht.spec.js | 72 +++++----------------------- 2 files changed, 14 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 63c4d1945..ce60a2f18 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/interface-ipfs-core/dht.spec.js b/test/interface-ipfs-core/dht.spec.js index c24ab049e..ed6c9a162 100644 --- a/test/interface-ipfs-core/dht.spec.js +++ b/test/interface-ipfs-core/dht.spec.js @@ -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)