Skip to content

Commit

Permalink
test: spec for submodules requiring (ipfs-inactive#544).
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofmn committed Jun 17, 2017
1 parent e9a8b29 commit c9beae4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 76 deletions.
76 changes: 0 additions & 76 deletions test/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const multiaddr = require('multiaddr')
const FactoryClient = require('./ipfs-factory/client')
const defaultConfig = require('../src/default-config')

describe('.bitswap', () => {
let ipfs
let fc
const nodeConfig = defaultConfig()

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
const nodeMaddr = multiaddr(ipfs.apiAddr).nodeAddress()
nodeConfig.host = nodeMaddr.address
nodeConfig.port = nodeMaddr.port
done()
})
})
Expand All @@ -42,18 +36,6 @@ describe('.bitswap', () => {
})
})

it('.wantlist (modular)', (done) => {
const wantlist = require('../src/api/bitswap/wantlist')(nodeConfig)

wantlist((err, res) => {
expect(err).to.not.exist()
expect(res).to.have.to.be.eql({
Keys: null
})
done()
})
})

it('.stat', (done) => {
ipfs.bitswap.stat((err, res) => {
expect(err).to.not.exist()
Expand All @@ -68,39 +50,13 @@ describe('.bitswap', () => {
})
})

it('.stat (modular)', (done) => {
const stat = require('../src/api/bitswap/stat')(nodeConfig)

stat((err, res) => {
expect(err).to.not.exist()
expect(res).to.have.property('BlocksReceived')
expect(res).to.have.property('DupBlksReceived')
expect(res).to.have.property('DupDataReceived')
expect(res).to.have.property('Peers')
expect(res).to.have.property('ProvideBufLen')
expect(res).to.have.property('Wantlist')

done()
})
})

it('.unwant', (done) => {
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.bitswap.unwant(key, (err) => {
expect(err).to.not.exist()
done()
})
})

it('.unwant (modular)', (done) => {
const unwant = require('../src/api/bitswap/unwant')(nodeConfig)

const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
unwant(key, (err) => {
expect(err).to.not.exist()
done()
})
})
})

describe('Promise API', () => {
Expand All @@ -113,17 +69,6 @@ describe('.bitswap', () => {
})
})

it('.wantlist (modular)', () => {
const wantlist = require('../src/api/bitswap/wantlist')(nodeConfig)

return wantlist()
.then((res) => {
expect(res).to.have.to.be.eql({
Keys: null
})
})
})

it('.stat', () => {
return ipfs.bitswap.stat()
.then((res) => {
Expand All @@ -136,30 +81,9 @@ describe('.bitswap', () => {
})
})

it('.stat (modular)', () => {
const stat = require('../src/api/bitswap/stat')(nodeConfig)

return stat()
.then((res) => {
expect(res).to.have.property('BlocksReceived')
expect(res).to.have.property('DupBlksReceived')
expect(res).to.have.property('DupDataReceived')
expect(res).to.have.property('Peers')
expect(res).to.have.property('ProvideBufLen')
expect(res).to.have.property('Wantlist')
})
})

it('.unwant', () => {
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
return ipfs.bitswap.unwant(key)
})

it('.unwant', () => {
const unwant = require('../src/api/bitswap/unwant')(nodeConfig)

const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
return unwant(key)
})
})
})
77 changes: 77 additions & 0 deletions test/sub-modules.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

describe('submodules', () => {
describe('bitswap', () => {
it('.wantlist', () => {
const wantlist = require('../src/api/bitswap/wantlist')
expect(wantlist).to.be.a('function')
})

it('.stat', () => {
const stat = require('../src/api/bitswap/stat')
expect(stat).to.be.a('function')
})

it('.unwant', () => {
const unwant = require('../src/api/bitswap/unwant')
expect(unwant).to.be.a('function')
})
})

describe('block', () => {
it('.get', () => {
const get = require('../src/api/block/get')
expect(get).to.be.a('function')
})

it('.stat', () => {
const stat = require('../src/api/block/stat')
expect(stat).to.be.a('function')
})

it('.put', () => {
const put = require('../src/api/block/put')
expect(put).to.be.a('function')
})
})

describe('bootstrap', () => {
it('.add', () => {
const add = require('../src/api/bootstrap/add')
expect(add).to.be.a('function')
})

it('.rm', () => {
const rm = require('../src/api/bootstrap/rm')
expect(rm).to.be.a('function')
})

it('.list', () => {
const list = require('../src/api/bootstrap/list')
expect(list).to.be.a('function')
})
})

describe('config', () => {
it('.get', () => {
const get = require('../src/api/config/get')
expect(get).to.be.a('function')
})

it('.set', () => {
const set = require('../src/api/config/set')
expect(set).to.be.a('function')
})

it('.replace', () => {
const replace = require('../src/api/config/replace')
expect(replace).to.be.a('function')
})
})
})

0 comments on commit c9beae4

Please sign in to comment.