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

Commit 2426072

Browse files
alanshawdaviddias
authored andcommitted
feat: modular interface tests (#785)
* feat: uses modular interface tests Reduces code repetition, allows test skipping and running only some tests. License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * feat: skip unimplemented files tests and add ls* tests License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: adds skips for #339 License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: adds skips for key and miscellaneous License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * feat: add types and util tests (skipped as currently failing) License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * feat: add pin tests License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix(pubsub): adds skips for tests on windows License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix(config): adds skip for config.replace License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: re-adds bitswap tests License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: move detect-node back to dependencies License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: add skip reasons License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: add reason for pubsub in browser skips License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: add bitswap skips for offline errors License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: remove skip for test that was removed License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update interface-ipfs-core version License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update deps and test on CI (#802) * chore: update interface-ipfs-core * fix(dag): `dag.put()` allows for optional options (#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 <pascal.precht@gmail.com> * fix(dag): fixes to allow options to be optional License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update ipfsd-ctl dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * 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 <alan@tableflip.io> * 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 <alan@tableflip.io>
1 parent a8f9a43 commit 2426072

22 files changed

+345
-596
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"glob": "^7.1.2",
3737
"ipfs-block": "~0.7.1",
3838
"ipfs-unixfs": "~0.1.15",
39-
"ipld-dag-cbor": "~0.12.0",
40-
"ipld-dag-pb": "~0.14.4",
39+
"ipld-dag-cbor": "~0.12.1",
40+
"ipld-dag-pb": "~0.14.5",
4141
"is-ipfs": "~0.3.2",
4242
"is-pull-stream": "0.0.0",
4343
"is-stream": "^1.1.0",
@@ -48,7 +48,7 @@
4848
"multihashes": "~0.4.13",
4949
"ndjson": "^1.5.0",
5050
"once": "^1.4.0",
51-
"peer-id": "~0.10.7",
51+
"peer-id": "~0.11.0",
5252
"peer-info": "~0.14.1",
5353
"promisify-es6": "^1.0.3",
5454
"pull-defer": "~0.2.2",
@@ -74,13 +74,13 @@
7474
"aegir": "^14.0.0",
7575
"browser-process-platform": "~0.1.1",
7676
"chai": "^4.1.2",
77-
"cross-env": "^5.1.6",
77+
"cross-env": "^5.2.0",
7878
"dirty-chai": "^2.0.1",
79-
"eslint-plugin-react": "^7.9.1",
79+
"eslint-plugin-react": "^7.10.0",
8080
"go-ipfs-dep": "~0.4.15",
8181
"gulp": "^3.9.1",
82-
"interface-ipfs-core": "~0.69.1",
83-
"ipfsd-ctl": "~0.37.3",
82+
"interface-ipfs-core": "~0.71.0",
83+
"ipfsd-ctl": "~0.37.5",
8484
"pull-stream": "^3.6.8",
8585
"socket.io": "^2.1.1",
8686
"socket.io-client": "^2.1.1",

src/dag/put.js

+40-27
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,67 @@ const dagCBOR = require('ipld-dag-cbor')
55
const promisify = require('promisify-es6')
66
const CID = require('cids')
77
const multihash = require('multihashes')
8-
const setImmediate = require('async/setImmediate')
98
const SendOneFile = require('../utils/send-one-file')
109

11-
function noop () {}
12-
1310
module.exports = (send) => {
1411
const sendOneFile = SendOneFile(send, 'dag/put')
1512

1613
return promisify((dagNode, options, callback) => {
1714
if (typeof options === 'function') {
18-
return setImmediate(() => callback(new Error('no options were passed')))
15+
callback = options
1916
}
2017

21-
callback = callback || noop
18+
options = options || {}
2219

23-
let hashAlg = options.hash || 'sha2-256'
24-
let format
25-
let inputEnc
20+
if (options.hash) {
21+
options.hashAlg = options.hash
22+
delete options.hash
23+
}
2624

27-
if (options.cid && CID.isCID(options.cid)) {
28-
format = options.cid.codec
29-
hashAlg = multihash.decode(options.cid.multihash).name
30-
prepare()
31-
} else if (options.format) {
32-
format = options.format
33-
prepare()
34-
} else {
35-
callback(new Error('Invalid arguments'))
25+
if (options.cid && (options.format || options.hashAlg)) {
26+
return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hash` options.'))
27+
} else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) {
28+
return callback(new Error('Can\'t put dag node. Please provide `format` AND `hash` options.'))
3629
}
3730

38-
function prepare () {
39-
inputEnc = 'raw'
31+
if (options.cid) {
32+
let cid
4033

41-
if (format === 'dag-cbor') {
42-
dagCBOR.util.serialize(dagNode, finalize)
43-
}
44-
if (format === 'dag-pb') {
45-
dagPB.util.serialize(dagNode, finalize)
34+
try {
35+
cid = new CID(options.cid)
36+
} catch (err) {
37+
return callback(err)
4638
}
39+
40+
options.format = cid.codec
41+
options.hashAlg = multihash.decode(cid.multihash).name
42+
delete options.cid
43+
}
44+
45+
const optionDefaults = {
46+
format: 'dag-cbor',
47+
hashAlg: 'sha2-256',
48+
inputEnc: 'raw'
49+
}
50+
51+
options = Object.assign(optionDefaults, options)
52+
53+
if (options.format === 'dag-cbor') {
54+
dagCBOR.util.serialize(dagNode, finalize)
55+
} else if (options.format === 'dag-pb') {
56+
dagPB.util.serialize(dagNode, finalize)
57+
} else {
58+
// FIXME Hopefully already serialized...can we use IPLD to serialise instead?
59+
finalize(null, dagNode)
4760
}
4861

4962
function finalize (err, serialized) {
5063
if (err) { return callback(err) }
5164
const sendOptions = {
5265
qs: {
53-
hash: hashAlg,
54-
format: format,
55-
'input-enc': inputEnc
66+
hash: options.hashAlg,
67+
format: options.format,
68+
'input-enc': options.inputEnc
5669
}
5770
}
5871
sendOneFile(serialized, sendOptions, (err, result) => {

test/interface.spec.js

+246
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const tests = require('interface-ipfs-core')
5+
const isNode = require('detect-node')
6+
const CommonFactory = require('./utils/interface-common-factory')
7+
const IPFSApi = require('../src')
8+
const isWindows = process.platform && process.platform === 'win32'
9+
10+
describe('interface-ipfs-core tests', () => {
11+
const defaultCommonFactory = CommonFactory.create()
12+
13+
tests.bitswap(defaultCommonFactory, {
14+
skip: [
15+
// bitswap.stat
16+
{
17+
name: 'should not get bitswap stats when offline',
18+
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
19+
},
20+
// bitswap.wantlist
21+
{
22+
name: 'should not get the wantlist when offline',
23+
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
24+
},
25+
// bitswap.unwant
26+
{
27+
name: 'should remove a key from the wantlist',
28+
reason: 'FIXME why is this skipped?'
29+
},
30+
{
31+
name: 'should not remove a key from the wantlist when offline',
32+
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
33+
}
34+
]
35+
})
36+
37+
tests.block(defaultCommonFactory)
38+
39+
tests.bootstrap(defaultCommonFactory)
40+
41+
tests.config(defaultCommonFactory, {
42+
skip: [
43+
// config.replace
44+
{
45+
name: 'replace',
46+
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'
47+
}
48+
]
49+
})
50+
51+
tests.dag(defaultCommonFactory, {
52+
skip: [
53+
// dag.tree
54+
{
55+
name: 'tree',
56+
reason: 'TODO vmx 2018-02-22: Currently the tree API is not exposed in go-ipfs'
57+
},
58+
// dag.get:
59+
{
60+
name: 'should get a dag-pb node local value',
61+
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'
62+
},
63+
{
64+
name: 'should get dag-pb value via dag-cbor node',
65+
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'
66+
},
67+
{
68+
name: 'should get by CID string + path',
69+
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'
70+
}
71+
]
72+
})
73+
74+
tests.dht(defaultCommonFactory, {
75+
skip: [
76+
// dht.findpeer
77+
{
78+
name: 'should fail to find other peer if peer does not exist',
79+
reason: 'FIXME checking what is exactly go-ipfs returning https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090'
80+
},
81+
// dht.findprovs
82+
{
83+
name: 'should provide from one node and find it through another node',
84+
reason: 'FIXME go-ipfs endpoint doesn\'t conform with the others https://github.com/ipfs/go-ipfs/issues/5047'
85+
},
86+
// dht.get
87+
{
88+
name: 'should get a value after it was put on another node',
89+
reason: 'FIXME go-ipfs errors with Error: key was not found (type 6) https://github.com/ipfs/go-ipfs/issues/3862'
90+
}
91+
]
92+
})
93+
94+
tests.files(defaultCommonFactory, {
95+
skip: [
96+
// files.add
97+
isNode ? null : {
98+
name: 'should add a nested directory as array of tupples',
99+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
100+
},
101+
isNode ? null : {
102+
name: 'should add a nested directory as array of tupples with progress',
103+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
104+
},
105+
// files.addPullStream
106+
isNode ? null : {
107+
name: 'should add pull stream of valid files and dirs',
108+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
109+
},
110+
// files.addReadableStream
111+
isNode ? null : {
112+
name: 'should add readable stream of valid files and dirs',
113+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
114+
},
115+
// files.catPullStream
116+
{
117+
name: 'should export a chunk of a file',
118+
reason: 'TODO not implemented in go-ipfs yet'
119+
},
120+
{
121+
name: 'should export a chunk of a file in a Pull Stream',
122+
reason: 'TODO not implemented in go-ipfs yet'
123+
},
124+
{
125+
name: 'should export a chunk of a file in a Readable Stream',
126+
reason: 'TODO not implemented in go-ipfs yet'
127+
},
128+
// files.get
129+
isNode ? null : {
130+
name: 'should get a directory',
131+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
132+
}
133+
]
134+
})
135+
136+
tests.key(defaultCommonFactory, {
137+
skip: [
138+
// key.export
139+
{
140+
name: 'export',
141+
reason: 'TODO not implemented in go-ipfs yet'
142+
},
143+
// key.import
144+
{
145+
name: 'import',
146+
reason: 'TODO not implemented in go-ipfs yet'
147+
}
148+
]
149+
})
150+
151+
tests.ls(defaultCommonFactory, {
152+
skip: [
153+
// lsPullStream
154+
isNode ? null : {
155+
name: 'should pull stream ls with a base58 encoded CID',
156+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
157+
},
158+
// lsReadableStream
159+
isNode ? null : {
160+
name: 'should readable stream ls with a base58 encoded CID',
161+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
162+
},
163+
// ls
164+
isNode ? null : {
165+
name: 'should ls with a base58 encoded CID',
166+
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
167+
}
168+
]
169+
})
170+
171+
tests.miscellaneous(defaultCommonFactory, {
172+
skip: [
173+
// stop
174+
{
175+
name: 'should stop the node',
176+
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
177+
}
178+
]
179+
})
180+
181+
tests.object(defaultCommonFactory)
182+
183+
tests.pin(defaultCommonFactory)
184+
185+
tests.ping(defaultCommonFactory)
186+
187+
tests.pubsub(CommonFactory.create({
188+
spawnOptions: {
189+
args: ['--enable-pubsub-experiment'],
190+
initOptions: { bits: 1024 }
191+
}
192+
}), {
193+
skip: isNode ? [
194+
// pubsub.subscribe
195+
isWindows ? {
196+
name: 'should send/receive 100 messages',
197+
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
198+
} : null,
199+
isWindows ? {
200+
name: 'should receive multiple messages',
201+
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
202+
} : null
203+
] : {
204+
reason: 'FIXME pubsub is not supported in the browser https://github.com/ipfs/js-ipfs-api/issues/518'
205+
}
206+
})
207+
208+
tests.repo(defaultCommonFactory)
209+
210+
tests.stats(defaultCommonFactory)
211+
212+
tests.swarm(CommonFactory.create({
213+
createSetup ({ ipfsFactory, nodes }) {
214+
return callback => {
215+
callback(null, {
216+
spawnNode (repoPath, config, cb) {
217+
if (typeof repoPath === 'function') {
218+
cb = repoPath
219+
repoPath = undefined
220+
}
221+
222+
if (typeof config === 'function') {
223+
cb = config
224+
config = undefined
225+
}
226+
227+
const spawnOptions = { repoPath, config, initOptions: { bits: 1024 } }
228+
229+
ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => {
230+
if (err) {
231+
return cb(err)
232+
}
233+
234+
nodes.push(_ipfsd)
235+
cb(null, IPFSApi(_ipfsd.apiAddr))
236+
})
237+
}
238+
})
239+
}
240+
}
241+
}))
242+
243+
tests.types(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })
244+
245+
tests.util(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })
246+
})

0 commit comments

Comments
 (0)