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

Commit

Permalink
refactor(tests): make each feature test isolated (launchable by itself
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 15, 2016
1 parent e5cb43c commit 0bee89f
Show file tree
Hide file tree
Showing 16 changed files with 400 additions and 153 deletions.
35 changes: 26 additions & 9 deletions test/interface-ipfs-core/block.spec.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
/* globals apiClients */
'use strict'

const FactoryClient = require('../factory/factory-client')
const expect = require('chai').expect

describe('.block', () => {
let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})

after((done) => {
fc.dismantle(done)
})

const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blorb = Buffer('blorb')

it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb], (err) => {
return ipfs.block.put([blorb, blorb], (err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', (done) => {
apiClients.a.block.put(blorb, (err, res) => {
ipfs.block.put(blorb, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
done()
})
})

it('block.get', (done) => {
apiClients.a.block.get(blorbKey, (err, res) => {
ipfs.block.get(blorbKey, (err, res) => {
expect(err).to.not.exist

let buf = ''
Expand All @@ -38,7 +55,7 @@ describe('.block', () => {
})

it('block.stat', (done) => {
apiClients.a.block.stat(blorbKey, (err, res) => {
ipfs.block.stat(blorbKey, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
Expand All @@ -48,21 +65,21 @@ describe('.block', () => {

describe('promise', () => {
it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb])
return ipfs.block.put([blorb, blorb])
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', () => {
return apiClients.a.block.put(blorb)
return ipfs.block.put(blorb)
.then((res) => {
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
})
})

it('block.get', (done) => {
apiClients.a.block.get(blorbKey)
ipfs.block.get(blorbKey)
.then((res) => {
let buf = ''
res
Expand All @@ -76,7 +93,7 @@ describe('.block', () => {
})

it('block.stat', () => {
return apiClients.a.block.stat(blorbKey)
return ipfs.block.stat(blorbKey)
.then((res) => {
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
Expand Down
55 changes: 36 additions & 19 deletions test/interface-ipfs-core/bootstrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
/* globals apiClients */
'use strict'

const expect = require('chai').expect
const FactoryClient = require('../factory/factory-client')

const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'

describe('.bootstrap', () => {
let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})

after((done) => {
fc.dismantle(done)
})

let peers

describe('.add', () => {
it('returns an error when called without args or options', (done) => {
return apiClients.a.bootstrap.add(null, (err) => {
return ipfs.bootstrap.add(null, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})

it('returns an error when called with an invalid arg', (done) => {
return apiClients.a.bootstrap.add(invalidArg, (err) => {
return ipfs.bootstrap.add(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})

it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
return apiClients.a.bootstrap.add(validIp4, (err, res) => {
return ipfs.bootstrap.add(validIp4, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
Expand All @@ -38,7 +55,7 @@ describe('.bootstrap', () => {
})

it('returns a list of bootstrap peers when called with the default option', (done) => {
return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => {
return ipfs.bootstrap.add(null, { default: true }, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
Expand All @@ -50,7 +67,7 @@ describe('.bootstrap', () => {

describe('.list', () => {
it('returns a list of peers', (done) => {
return apiClients.a.bootstrap.list((err, res) => {
return ipfs.bootstrap.list((err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
Expand All @@ -61,14 +78,14 @@ describe('.bootstrap', () => {

describe('.rm', () => {
it('returns an error when called with an invalid arg', (done) => {
return apiClients.a.bootstrap.rm(invalidArg, (err) => {
return ipfs.bootstrap.rm(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})

it('returns empty list because no peers removed when called without an arg or options', (done) => {
return apiClients.a.bootstrap.rm(null, (err, res) => {
return ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
Expand All @@ -78,7 +95,7 @@ describe('.bootstrap', () => {
})

it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
return apiClients.a.bootstrap.rm(null, (err, res) => {
return ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
Expand All @@ -88,7 +105,7 @@ describe('.bootstrap', () => {
})

it('returns list of all peers removed when all option is passed', (done) => {
return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => {
return ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
Expand All @@ -100,21 +117,21 @@ describe('.bootstrap', () => {
describe('.promise', () => {
describe('.add', () => {
it('returns an error when called without args or options', () => {
return apiClients.a.bootstrap.add(null)
return ipfs.bootstrap.add(null)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('returns an error when called with an invalid arg', () => {
return apiClients.a.bootstrap.add(invalidArg)
return ipfs.bootstrap.add(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('returns a list of peers when called with a valid arg (ip4)', () => {
return apiClients.a.bootstrap.add(validIp4)
return ipfs.bootstrap.add(validIp4)
.then((res) => {
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
Expand All @@ -124,7 +141,7 @@ describe('.bootstrap', () => {
})

it('returns a list of default peers when called with the default option', () => {
return apiClients.a.bootstrap.add(null, { default: true })
return ipfs.bootstrap.add(null, { default: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
Expand All @@ -135,7 +152,7 @@ describe('.bootstrap', () => {

describe('.list', () => {
it('returns a list of peers', () => {
return apiClients.a.bootstrap.list()
return ipfs.bootstrap.list()
.then((res) => {
peers = res.Peers
expect(peers).to.exist
Expand All @@ -145,14 +162,14 @@ describe('.bootstrap', () => {

describe('.rm', () => {
it('returns an error when called with an invalid arg', () => {
return apiClients.a.bootstrap.rm(invalidArg)
return ipfs.bootstrap.rm(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('returns empty list when called without an arg or options', () => {
return apiClients.a.bootstrap.rm(null)
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
Expand All @@ -161,7 +178,7 @@ describe('.bootstrap', () => {
})

it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
return apiClients.a.bootstrap.rm(null)
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
Expand All @@ -170,7 +187,7 @@ describe('.bootstrap', () => {
})

it('returns list of all peers removed when all option is passed', () => {
return apiClients.a.bootstrap.rm(null, { all: true })
return ipfs.bootstrap.rm(null, { all: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
Expand Down
23 changes: 20 additions & 3 deletions test/interface-ipfs-core/commands.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
/* eslint-env mocha */
/* globals apiClients */
'use strict'

const expect = require('chai').expect
const FactoryClient = require('../factory/factory-client')

describe('.commands', () => {
let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})

after((done) => {
fc.dismantle(done)
})

it('lists commands', (done) => {
apiClients.a.commands((err, res) => {
ipfs.commands((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
done()
Expand All @@ -15,7 +32,7 @@ describe('.commands', () => {

describe('promise', () => {
it('lists commands', () => {
return apiClients.a.commands()
return ipfs.commands()
.then((res) => {
expect(res).to.exist
})
Expand Down
31 changes: 24 additions & 7 deletions test/interface-ipfs-core/diag.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
/* eslint-env mocha */
/* globals apiClients */
'use strict'

const FactoryClient = require('../factory/factory-client')
const expect = require('chai').expect

describe('.diag', () => {
let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})

after((done) => {
fc.dismantle(done)
})

it('.diag.net', (done) => {
apiClients.a.diag.net((err, res) => {
ipfs.diag.net((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
done()
})
})

it('.diag.sys', (done) => {
apiClients.a.diag.sys((err, res) => {
ipfs.diag.sys((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
expect(res).to.have.a.property('memory')
Expand All @@ -24,7 +41,7 @@ describe('.diag', () => {
})

it('.diag.cmds', (done) => {
apiClients.a.diag.cmds((err, res) => {
ipfs.diag.cmds((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
done()
Expand All @@ -33,14 +50,14 @@ describe('.diag', () => {

describe('promise', () => {
it('.diag.net', () => {
return apiClients.a.diag.net()
return ipfs.diag.net()
.then((res) => {
expect(res).to.exist
})
})

it('.diag.sys', () => {
return apiClients.a.diag.sys()
return ipfs.diag.sys()
.then((res) => {
expect(res).to.exist
expect(res).to.have.a.property('memory')
Expand All @@ -49,7 +66,7 @@ describe('.diag', () => {
})

it('.diag.cmds', () => {
return apiClients.a.diag.cmds()
return ipfs.diag.cmds()
.then((res) => {
expect(res).to.exist
})
Expand Down
Loading

0 comments on commit 0bee89f

Please sign in to comment.