This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modularise tests by command, add tools to skip and only (#290)
BREAKING CHANGE: Consumers of this test suite now have fine grained control over what tests are run. Tests can now be skipped and "onlyed" (run only specific tests). This can be done on a test, command and sub-system level. See the updated usage guide for instructions: https://github.com/ipfs/interface-ipfs-core/blob/master/README.md#usage. This means that tests skips depending on implementation (e.g. go/js), environment (e.g. node/browser) or platform (e.g. macOS/linux/windows) that were previously present in this suite have been removed. Consumers of this library should add their own skips based on the implementation that's being tested and the environment/platform that the tests are running on. The following other breaking changes have been made: 1. The common object passed to test suites has changed. It must now be a function that returns a common object (same shape and functions as before). 2. The `ipfs.ls` tests (not MFS `ipfs.files.ls`) is now a root level suite. You'll need to import it and use like `tests.ls(createCommon)` to have those tests run. 3. The `generic` suite (an alias to `miscellaneous`) has been removed. See #290 for more details. License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
- Loading branch information
Showing
135 changed files
with
8,407 additions
and
5,860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.