Skip to content

Commit

Permalink
feat: modular interface tests (ipfs-inactive#785)
Browse files Browse the repository at this point in the history
* feat: uses modular interface tests

    Reduces code repetition, allows test skipping and running only some tests.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* feat: skip unimplemented files tests and add ls* tests

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: adds skips for ipfs-inactive#339

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: adds skips for key and miscellaneous

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* feat: add types and util tests (skipped as currently failing)

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* feat: add pin tests

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix(pubsub): adds skips for tests on windows

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix(config): adds skip for config.replace

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: re-adds bitswap tests

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: move detect-node back to dependencies

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: add skip reasons

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: update interface-ipfs-core dependency

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: add reason for pubsub in browser skips

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: add bitswap skips for offline errors

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: remove skip for test that was removed

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: update interface-ipfs-core version

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: update deps and test on CI (ipfs-inactive#802)

* chore: update interface-ipfs-core

* fix(dag): `dag.put()` allows for optional options (ipfs-inactive#801)

* fix(dag): ensure `dag.put()` allows for optional options

This is to align with API changes made in

ipfs-inactive/interface-js-ipfs-core@011c417

and

ipfs/js-ipfs#1415

License: MIT
Signed-off-by: Pascal Precht <[email protected]>

* fix(dag): fixes to allow options to be optional

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: update interface-ipfs-core dependency

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: update ipfsd-ctl dependency

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: increase timeout for addFromURL with wrap-with-directory

Sadly we can't guarantee ipfs.io will respond within 5s

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: skip bitswap offline tests on all platforms

The offline tests create and stop a node. ipfs/kubo#4078 seems to not only be restricted to windows.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
alanshaw authored and danieldaf committed Jul 21, 2018
1 parent a7de3d8 commit 9c9dd25
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 596 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"glob": "^7.1.2",
"ipfs-block": "~0.7.1",
"ipfs-unixfs": "~0.1.15",
"ipld-dag-cbor": "~0.12.0",
"ipld-dag-pb": "~0.14.4",
"ipld-dag-cbor": "~0.12.1",
"ipld-dag-pb": "~0.14.5",
"is-ipfs": "~0.3.2",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
Expand All @@ -48,7 +48,7 @@
"multihashes": "~0.4.13",
"ndjson": "^1.5.0",
"once": "^1.4.0",
"peer-id": "~0.10.7",
"peer-id": "~0.11.0",
"peer-info": "~0.14.1",
"promisify-es6": "^1.0.3",
"pull-defer": "~0.2.2",
Expand All @@ -74,13 +74,13 @@
"aegir": "^14.0.0",
"browser-process-platform": "~0.1.1",
"chai": "^4.1.2",
"cross-env": "^5.1.6",
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.9.1",
"eslint-plugin-react": "^7.10.0",
"go-ipfs-dep": "~0.4.15",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.69.1",
"ipfsd-ctl": "~0.37.3",
"interface-ipfs-core": "~0.71.0",
"ipfsd-ctl": "~0.37.5",
"pull-stream": "^3.6.8",
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1",
Expand Down
67 changes: 40 additions & 27 deletions src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,67 @@ const dagCBOR = require('ipld-dag-cbor')
const promisify = require('promisify-es6')
const CID = require('cids')
const multihash = require('multihashes')
const setImmediate = require('async/setImmediate')
const SendOneFile = require('../utils/send-one-file')

function noop () {}

module.exports = (send) => {
const sendOneFile = SendOneFile(send, 'dag/put')

return promisify((dagNode, options, callback) => {
if (typeof options === 'function') {
return setImmediate(() => callback(new Error('no options were passed')))
callback = options
}

callback = callback || noop
options = options || {}

let hashAlg = options.hash || 'sha2-256'
let format
let inputEnc
if (options.hash) {
options.hashAlg = options.hash
delete options.hash
}

if (options.cid && CID.isCID(options.cid)) {
format = options.cid.codec
hashAlg = multihash.decode(options.cid.multihash).name
prepare()
} else if (options.format) {
format = options.format
prepare()
} else {
callback(new Error('Invalid arguments'))
if (options.cid && (options.format || options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hash` options.'))
} else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide `format` AND `hash` options.'))
}

function prepare () {
inputEnc = 'raw'
if (options.cid) {
let cid

if (format === 'dag-cbor') {
dagCBOR.util.serialize(dagNode, finalize)
}
if (format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
try {
cid = new CID(options.cid)
} catch (err) {
return callback(err)
}

options.format = cid.codec
options.hashAlg = multihash.decode(cid.multihash).name
delete options.cid
}

const optionDefaults = {
format: 'dag-cbor',
hashAlg: 'sha2-256',
inputEnc: 'raw'
}

options = Object.assign(optionDefaults, options)

if (options.format === 'dag-cbor') {
dagCBOR.util.serialize(dagNode, finalize)
} else if (options.format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
} else {
// FIXME Hopefully already serialized...can we use IPLD to serialise instead?
finalize(null, dagNode)
}

function finalize (err, serialized) {
if (err) { return callback(err) }
const sendOptions = {
qs: {
hash: hashAlg,
format: format,
'input-enc': inputEnc
hash: options.hashAlg,
format: options.format,
'input-enc': options.inputEnc
}
}
sendOneFile(serialized, sendOptions, (err, result) => {
Expand Down
246 changes: 246 additions & 0 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/* eslint-env mocha */
'use strict'

const tests = require('interface-ipfs-core')
const isNode = require('detect-node')
const CommonFactory = require('./utils/interface-common-factory')
const IPFSApi = require('../src')
const isWindows = process.platform && process.platform === 'win32'

describe('interface-ipfs-core tests', () => {
const defaultCommonFactory = CommonFactory.create()

tests.bitswap(defaultCommonFactory, {
skip: [
// bitswap.stat
{
name: 'should not get bitswap stats when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
},
// bitswap.wantlist
{
name: 'should not get the wantlist when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
},
// bitswap.unwant
{
name: 'should remove a key from the wantlist',
reason: 'FIXME why is this skipped?'
},
{
name: 'should not remove a key from the wantlist when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
}
]
})

tests.block(defaultCommonFactory)

tests.bootstrap(defaultCommonFactory)

tests.config(defaultCommonFactory, {
skip: [
// config.replace
{
name: 'replace',
reason: 'FIXME Waiting for fix on go-ipfs https://github.com/ipfs/js-ipfs-api/pull/307#discussion_r69281789 and https://github.com/ipfs/go-ipfs/issues/2927'
}
]
})

tests.dag(defaultCommonFactory, {
skip: [
// dag.tree
{
name: 'tree',
reason: 'TODO vmx 2018-02-22: Currently the tree API is not exposed in go-ipfs'
},
// dag.get:
{
name: 'should get a dag-pb node local value',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
},
{
name: 'should get dag-pb value via dag-cbor node',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
},
{
name: 'should get by CID string + path',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
}
]
})

tests.dht(defaultCommonFactory, {
skip: [
// dht.findpeer
{
name: 'should fail to find other peer if peer does not exist',
reason: 'FIXME checking what is exactly go-ipfs returning https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090'
},
// dht.findprovs
{
name: 'should provide from one node and find it through another node',
reason: 'FIXME go-ipfs endpoint doesn\'t conform with the others https://github.com/ipfs/go-ipfs/issues/5047'
},
// dht.get
{
name: 'should get a value after it was put on another node',
reason: 'FIXME go-ipfs errors with Error: key was not found (type 6) https://github.com/ipfs/go-ipfs/issues/3862'
}
]
})

tests.files(defaultCommonFactory, {
skip: [
// files.add
isNode ? null : {
name: 'should add a nested directory as array of tupples',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
isNode ? null : {
name: 'should add a nested directory as array of tupples with progress',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.addPullStream
isNode ? null : {
name: 'should add pull stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.addReadableStream
isNode ? null : {
name: 'should add readable stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.catPullStream
{
name: 'should export a chunk of a file',
reason: 'TODO not implemented in go-ipfs yet'
},
{
name: 'should export a chunk of a file in a Pull Stream',
reason: 'TODO not implemented in go-ipfs yet'
},
{
name: 'should export a chunk of a file in a Readable Stream',
reason: 'TODO not implemented in go-ipfs yet'
},
// files.get
isNode ? null : {
name: 'should get a directory',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
}
]
})

tests.key(defaultCommonFactory, {
skip: [
// key.export
{
name: 'export',
reason: 'TODO not implemented in go-ipfs yet'
},
// key.import
{
name: 'import',
reason: 'TODO not implemented in go-ipfs yet'
}
]
})

tests.ls(defaultCommonFactory, {
skip: [
// lsPullStream
isNode ? null : {
name: 'should pull stream ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// lsReadableStream
isNode ? null : {
name: 'should readable stream ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// ls
isNode ? null : {
name: 'should ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
}
]
})

tests.miscellaneous(defaultCommonFactory, {
skip: [
// stop
{
name: 'should stop the node',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
}
]
})

tests.object(defaultCommonFactory)

tests.pin(defaultCommonFactory)

tests.ping(defaultCommonFactory)

tests.pubsub(CommonFactory.create({
spawnOptions: {
args: ['--enable-pubsub-experiment'],
initOptions: { bits: 1024 }
}
}), {
skip: isNode ? [
// pubsub.subscribe
isWindows ? {
name: 'should send/receive 100 messages',
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
} : null,
isWindows ? {
name: 'should receive multiple messages',
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
} : null
] : {
reason: 'FIXME pubsub is not supported in the browser https://github.com/ipfs/js-ipfs-api/issues/518'
}
})

tests.repo(defaultCommonFactory)

tests.stats(defaultCommonFactory)

tests.swarm(CommonFactory.create({
createSetup ({ ipfsFactory, nodes }) {
return callback => {
callback(null, {
spawnNode (repoPath, config, cb) {
if (typeof repoPath === 'function') {
cb = repoPath
repoPath = undefined
}

if (typeof config === 'function') {
cb = config
config = undefined
}

const spawnOptions = { repoPath, config, initOptions: { bits: 1024 } }

ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, IPFSApi(_ipfsd.apiAddr))
})
}
})
}
}
}))

tests.types(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })

tests.util(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })
})
Loading

0 comments on commit 9c9dd25

Please sign in to comment.