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

feat: modularise tests by command, add tools to skip and only #290

Merged
merged 41 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8ebf438
feat: modularise block, add mocha and test suite utils
alanshaw Jun 2, 2018
1cc38ef
fix: isolated block tests
alanshaw Jun 4, 2018
269df8c
docs: updates code examples
alanshaw Jun 4, 2018
949b64c
feat(bootstrap): modularised bootstrap tests
alanshaw Jun 4, 2018
c17e194
feat(config): modularise config
alanshaw Jun 4, 2018
bf9a671
feat(dag): modularise dag
alanshaw Jun 5, 2018
72d03a8
feat: skip or only specific tests
alanshaw Jun 5, 2018
3cd7f4e
fix: removes implementation specific skips
alanshaw Jun 5, 2018
4c7adbc
feat(dht): modularise DHT
alanshaw Jun 5, 2018
3a5afe5
feat(files): modularised files
alanshaw Jun 6, 2018
a3008e6
feat(files): isolate MFS tests
alanshaw Jun 6, 2018
0996d7c
fix: removes platform specific skips
alanshaw Jun 6, 2018
850bf61
feat(key): modularised key
alanshaw Jun 6, 2018
dd0cb8e
feat: modularises miscellaneous
alanshaw Jun 6, 2018
f861431
feat: modularised ping
alanshaw Jun 6, 2018
dd288ec
feat: modularised repo and stats
alanshaw Jun 7, 2018
f086eb4
chore: move repeated fixtures into utils module
alanshaw Jun 7, 2018
f634c14
chore: use files fixtures in ls tests
alanshaw Jun 7, 2018
b42a54b
feat: modularised types and util
alanshaw Jun 7, 2018
9318dbc
feat: modularises object.patch* and object.new
alanshaw Jun 7, 2018
93f51dc
feat: modularise object.data,get,links,put and stat
alanshaw Jun 7, 2018
96cf49a
feat(pin): modularises pin
alanshaw Jun 7, 2018
c60ceb2
chore: cleanup requires
alanshaw Jun 7, 2018
bb72445
feat: modularises pubsub
alanshaw Jun 8, 2018
fb8719b
feat(swarm): modularise swarm
alanshaw Jun 8, 2018
b12fb09
chore: fix warning for new Buffer
alanshaw Jun 8, 2018
b969416
fix: import small file fixture
alanshaw Jun 8, 2018
a8492f2
fix: swarm peers suite name
alanshaw Jun 13, 2018
3eda55d
fix: spawn only as many nodes as needed
alanshaw Jun 13, 2018
1615831
chore: remove safe-buffer
alanshaw Jun 19, 2018
5567ddf
chore: move expect into mocha util
alanshaw Jun 19, 2018
0f61c26
chore: move invalidArg var into exported function
alanshaw Jun 19, 2018
eb9e785
chore: prefer arrow functions
alanshaw Jun 19, 2018
965bdcb
test: add test for retreive empty block
alanshaw Jun 22, 2018
2c75978
chore: re-add bitswap tests
alanshaw Jun 25, 2018
57418b1
chore: do not rely on discovery for ping tests
alanshaw Jun 26, 2018
22d9b00
feat: allow skip reasons to be passed
alanshaw Jun 26, 2018
a3d3f5c
fix: pin.rm suite name
alanshaw Jun 26, 2018
4f9b635
chore: remove unnecessary describe block
alanshaw Jun 26, 2018
7a9c4d0
fix: ensure there is another node to provide to
alanshaw Jun 26, 2018
616a3e0
fix: remove old unused bitswap tests
alanshaw Jun 27, 2018
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
82 changes: 72 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Include this badge in your readme if you make a new module that implements inter
## Install

In JavaScript land:

```js
npm install interface-ipfs-core
```
Expand All @@ -68,20 +69,81 @@ In Go land:

Install `interface-ipfs-core` as one of the dependencies of your project and as a test file. Then, using `mocha` (for Node.js) or a test runner with compatible API, do:

```
var test = require('interface-ipfs-core')

var common = {
setup: function (cb) {
cb(null, IPFSFactory)
```js
const tests = require('interface-ipfs-core')

// Create common setup and teardown
const createCommon = () => ({
// Do some setup common to all tests
setup (cb) {
// Must call back with an "IPFS factory", an object with a `spawnNode` method
cb(null, {
// Use ipfsd-ctl or other to spawn an IPFS node for testing
spawnNode (cb) { /* ... */ }
})
},
teardown: function (cb) {
// Dispose of nodes created by the IPFS factory and any other teardown
teardown (cb) {
cb()
}
}
})

tests.block(createCommon)
tests.config(createCommon)
tests.dag(createCommon)
// ...etc. (see js/src/index.js)
```

#### Running tests by command

```js
tests.repo.version(createCommon)
```

#### Skipping tests

```js
tests.repo.gc(createCommon, { skip: true }) // pass an options object to skip these tests

// OR, at the subsystem level

// skips ALL the repo.gc tests
tests.repo(createCommon, { skip: ['gc'] })
// skips ALL the object.patch.addLink tests
tests.object(createCommon, { skip: ['patch.addLink'] })
```

##### Skipping specific tests

```js
tests.repo.gc(createCommon, { skip: ['should do a thing'] }) // named test(s) to skip

// OR, at the subsystem level

tests.repo(createCommon, { skip: ['should do a thing'] })
```

#### Running only some tests

```js
tests.repo.gc(createCommon, { only: true }) // pass an options object to run only these tests

// OR, at the subsystem level

// runs only ALL the repo.gc tests
tests.repo(createCommon, { only: ['gc'] })
// runs only ALL the object.patch.addLink tests
tests.object(createCommon, { only: ['patch.addLink'] })
```

##### Running only specific tests

```js
tests.repo.gc(createCommon, { only: ['should do a thing'] }) // only run these named test(s)

// OR, at the subsystem level

// use all of the test suits
test.all(common)
tests.repo(createCommon, { only: ['should do a thing'] })
```

### Go
Expand Down
144 changes: 0 additions & 144 deletions js/src/bitswap.js

This file was deleted.

10 changes: 10 additions & 0 deletions js/src/bitswap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'
const { createSuite } = require('../utils/suite')

const tests = {
stat: require('./stat'),
wantlist: require('./wantlist'),
unwant: require('./unwant')
}

module.exports = createSuite(tests)
62 changes: 62 additions & 0 deletions js/src/bitswap/stat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-env mocha */
'use strict'

const waterfall = require('async/waterfall')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsBitswap } = require('../stats/utils')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.bitswap.stat', () => {
let ipfs

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
})

after((done) => common.teardown(done))

it('should get bitswap stats', (done) => {
ipfs.bitswap.stat((err, res) => {
expectIsBitswap(err, res)
done()
})
})

it('should get bitswap stats (promised)', () => {
return ipfs.bitswap.stat().then((res) => {
expectIsBitswap(null, res)
})
})

it('should not get bitswap stats when offline', function (done) {
this.timeout(60 * 1000)

waterfall([
(cb) => createCommon().setup(cb),
(factory, cb) => factory.spawnNode(cb),
(node, cb) => node.stop((err) => cb(err, node))
], (err, node) => {
expect(err).to.not.exist()
node.bitswap.wantlist((err) => {
expect(err).to.exist()
done()
})
})
})
})
}
75 changes: 75 additions & 0 deletions js/src/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-env mocha */
'use strict'

const waterfall = require('async/waterfall')
const { spawnNodesWithId } = require('../utils/spawn')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { waitForWantlistKey } = require('./utils')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.bitswap.unwant', () => {
let ipfsA
let ipfsB
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist()

spawnNodesWithId(2, factory, (err, nodes) => {
expect(err).to.not.exist()

ipfsA = nodes[0]
ipfsB = nodes[1]

// Add key to the wantlist for ipfsB
ipfsB.block.get(key, () => {})

ipfsA.swarm.connect(ipfsB.peerId.addresses[0], done)
})
})
})

after((done) => common.teardown(done))

it('should remove a key from the wantlist', (done) => {
waitForWantlistKey(ipfsB, key, (err) => {
expect(err).to.not.exist()

ipfsB.bitswap.unwant(key, (err) => {
expect(err).to.not.exist()

ipfsB.bitswap.wantlist((err, list) => {
expect(err).to.not.exist()
expect(list.Keys.every(k => k['/'] !== key)).to.equal(true)
done()
})
})
})
})

it('should not remove a key from the wantlist when offline', function (done) {
this.timeout(60 * 1000)

waterfall([
(cb) => createCommon().setup(cb),
(factory, cb) => factory.spawnNode(cb),
(node, cb) => node.stop((err) => cb(err, node))
], (err, node) => {
expect(err).to.not.exist()
node.bitswap.wantlist((err) => {
expect(err).to.exist()
done()
})
})
})
})
}
Loading