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

Commit fa042d3

Browse files
committed
test: add missing tests
Our http tests in `js-IPFS` duplicate a whole bunch of tests from this suite, but they also test some unhappy paths that this suite does not. I've pulled them out of `js-IPFS` as part of ipfs/js-ipfs#2495 and am adding them to the interface tests here.
1 parent 3e53cfb commit fa042d3

File tree

13 files changed

+222
-0
lines changed

13 files changed

+222
-0
lines changed

src/block/get.js

+8
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,13 @@ module.exports = (createCommon, options) => {
107107
})
108108
})
109109
})
110+
111+
it('should return an error for an invalid CID', () => {
112+
return ipfs.block.get('invalid')
113+
.then(
114+
() => expect.fail('should have returned an error for invalid argument'),
115+
(err) => expect(err).to.be.an.instanceof(Error)
116+
)
117+
})
110118
})
111119
}

src/block/stat.js

+16
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,21 @@ module.exports = (createCommon, options) => {
4343
done()
4444
})
4545
})
46+
47+
it('should return error for missing argument', () => {
48+
return ipfs.block.stat(null)
49+
.then(
50+
() => expect.fail('should have thrown for missing parameter'),
51+
(err) => expect(err).to.be.an.instanceof(Error)
52+
)
53+
})
54+
55+
it('should return error for invalid argument', () => {
56+
return ipfs.block.stat('invalid')
57+
.then(
58+
() => expect.fail('should have thrown for invalid parameter'),
59+
(err) => expect(err).to.be.an.instanceof(Error)
60+
)
61+
})
4662
})
4763
}

src/bootstrap/add.js

+15
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,20 @@ module.exports = (createCommon, options) => {
6060
done()
6161
})
6262
})
63+
64+
it('should prevent duplicate inserts of bootstrap peers', async () => {
65+
const removed = await ipfs.bootstrap.rm(null, { all: true })
66+
expect(removed).to.have.property('Peers').that.is.an('array')
67+
expect(removed.Peers).to.have.lengthOf(0)
68+
69+
const added = await ipfs.bootstrap.add(validIp4)
70+
expect(added).to.have.property('Peers').that.deep.equals([validIp4])
71+
72+
const addedAgain = await ipfs.bootstrap.add(validIp4)
73+
expect(addedAgain).to.have.property('Peers').that.deep.equals([validIp4])
74+
75+
const list = await ipfs.bootstrap.list()
76+
expect(list).to.have.property('Peers').that.deep.equals([validIp4])
77+
})
6378
})
6479
}

src/config/set.js

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ module.exports = (createCommon, options) => {
7272
})
7373
})
7474

75+
it('should set a boolean', async () => {
76+
const value = true
77+
const key = 'Datastore.Path'
78+
79+
await ipfs.config.set(key, value)
80+
expect(await ipfs.config.get(key)).to.equal(value)
81+
})
82+
83+
it('should set the other boolean', async () => {
84+
const value = false
85+
const key = 'Datastore.Path'
86+
87+
await ipfs.config.set(key, value)
88+
expect(await ipfs.config.get(key)).to.equal(value)
89+
})
90+
7591
it('should set a JSON object', (done) => {
7692
const key = 'API.HTTPHeaders.Access-Control-Allow-Origin'
7793
const val = ['http://example.io']

src/files-mfs/ls.js

+24
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,29 @@ module.exports = (createCommon, options) => {
9191
})
9292
})
9393
})
94+
95+
it('should list an empty directory', async () => {
96+
const testDir = `/test-${hat()}`
97+
await ipfs.files.mkdir(testDir)
98+
const contents = await ipfs.files.ls(testDir)
99+
100+
expect(contents).to.be.an('array').and.to.be.empty()
101+
})
102+
103+
it('should list an file directly', async () => {
104+
const fileName = `single-file-${hat()}.txt`
105+
const filePath = `/${fileName}`
106+
await ipfs.files.write(filePath, Buffer.from('Hello world'), {
107+
create: true
108+
})
109+
const contents = await ipfs.files.ls(filePath)
110+
111+
expect(contents).to.be.an('array').and.have.lengthOf(1).and.to.deep.equal([{
112+
hash: '',
113+
name: fileName,
114+
size: 0,
115+
type: 0
116+
}])
117+
})
94118
})
95119
}

src/object/data.js

+16
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,21 @@ module.exports = (createCommon, options) => {
118118
})
119119
})
120120
})
121+
122+
it('returns error for request without argument', () => {
123+
return ipfs.object.data(null)
124+
.then(
125+
() => expect.fail('should have returned an error for invalid argument'),
126+
(err) => expect(err).to.be.an.instanceof(Error)
127+
)
128+
})
129+
130+
it('returns error for request with invalid argument', () => {
131+
ipfs.object.data('invalid', { enc: 'base58' })
132+
.then(
133+
() => expect.fail('should have returned an error for invalid argument'),
134+
(err) => expect(err).to.be.an.instanceof(Error)
135+
)
136+
})
121137
})
122138
}

src/object/get.js

+16
Original file line numberDiff line numberDiff line change
@@ -336,5 +336,21 @@ module.exports = (createCommon, options) => {
336336
expect(meta.fileSize()).to.equal(data.length)
337337
})
338338
})
339+
340+
it('should error for request without argument', () => {
341+
return ipfs.object.get(null)
342+
.then(
343+
() => expect.fail('should have returned an error for invalid argument'),
344+
(err) => expect(err).to.be.an.instanceof(Error)
345+
)
346+
})
347+
348+
it('returns error for request with invalid argument', () => {
349+
return ipfs.object.get('invalid', { enc: 'base58' })
350+
.then(
351+
() => expect.fail('should have returned an error for invalid argument'),
352+
(err) => expect(err).to.be.an.instanceof(Error)
353+
)
354+
})
339355
})
340356
}

src/object/links.js

+16
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,21 @@ module.exports = (createCommon, options) => {
206206
})
207207
})
208208
})
209+
210+
it('returns error for request without argument', () => {
211+
return ipfs.object.links(null)
212+
.then(
213+
() => expect.fail('should have returned an error for invalid argument'),
214+
(err) => expect(err).to.be.an.instanceof(Error)
215+
)
216+
})
217+
218+
it('returns error for request with invalid argument', () => {
219+
ipfs.object.links('invalid', { enc: 'base58' })
220+
.then(
221+
() => expect.fail('should have returned an error for invalid argument'),
222+
(err) => expect(err).to.be.an.instanceof(Error)
223+
)
224+
})
209225
})
210226
}

src/object/patch/add-link.js

+16
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,21 @@ module.exports = (createCommon, options) => {
163163

164164
expect(newParentCid).to.eql(nodeFromObjectPatchCid)
165165
})
166+
167+
it('returns error for request without arguments', () => {
168+
return ipfs.object.patch.addLink(null, null, null)
169+
.then(
170+
() => expect.fail('should have returned an error for invalid argument'),
171+
(err) => expect(err).to.be.an.instanceof(Error)
172+
)
173+
})
174+
175+
it('returns error for request with only one invalid argument', () => {
176+
return ipfs.object.patch.addLink('invalid', null, null)
177+
.then(
178+
() => expect.fail('should have returned an error for invalid argument'),
179+
(err) => expect(err).to.be.an.instanceof(Error)
180+
)
181+
})
166182
})
167183
}

src/object/patch/append-data.js

+18
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,23 @@ module.exports = (createCommon, options) => {
5959

6060
expect(nodeCid).to.not.deep.equal(patchedNodeCid)
6161
})
62+
63+
it('returns error for request without key & data', () => {
64+
return ipfs.object.patch.appendData(null, null)
65+
.then(
66+
() => expect.fail('should have returned an error for invalid argument'),
67+
(err) => expect(err).to.be.an.instanceof(Error)
68+
)
69+
})
70+
71+
it('returns error for request without data', () => {
72+
const filePath = 'test/fixtures/test-data/badnode.json'
73+
74+
return ipfs.object.patch.appendData(null, filePath)
75+
.then(
76+
() => expect.fail('should have returned an error for invalid argument'),
77+
(err) => expect(err).to.be.an.instanceof(Error)
78+
)
79+
})
6280
})
6381
}

src/object/patch/rm-link.js

+27
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,32 @@ module.exports = (createCommon, options) => {
121121
expect(withoutChildCid).to.not.deep.equal(parentCid)
122122
expect(withoutChildCid).to.deep.equal(nodeCid)
123123
})
124+
125+
it('returns error for request without arguments', () => {
126+
return ipfs.object.patch.rmLink(null, null)
127+
.then(
128+
() => expect.fail('should have returned an error for invalid argument'),
129+
(err) => expect(err).to.be.an.instanceof(Error)
130+
)
131+
})
132+
133+
it('returns error for request only one invalid argument', () => {
134+
return ipfs.object.patch.rmLink('invalid', null)
135+
.then(
136+
() => expect.fail('should have returned an error for invalid argument'),
137+
(err) => expect(err).to.be.an.instanceof(Error)
138+
)
139+
})
140+
141+
it('returns error for request with invalid first argument', () => {
142+
const root = ''
143+
const link = 'foo'
144+
145+
return ipfs.object.patch.rmLink(root, link)
146+
.then(
147+
() => expect.fail('should have returned an error for invalid argument'),
148+
(err) => expect(err).to.be.an.instanceof(Error)
149+
)
150+
})
124151
})
125152
}

src/object/patch/set-data.js

+18
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,23 @@ module.exports = (createCommon, options) => {
6868
expect(nodeCid).to.not.deep.equal(patchedNodeCid)
6969
expect(patchedNode.Data).to.eql(patchData)
7070
})
71+
72+
it('returns error for request without key & data', () => {
73+
return ipfs.object.patch.setData(null, null)
74+
.then(
75+
() => expect.fail('should have returned an error for invalid argument'),
76+
(err) => expect(err).to.be.an.instanceof(Error)
77+
)
78+
})
79+
80+
it('returns error for request without data', () => {
81+
const filePath = 'test/fixtures/test-data/badnode.json'
82+
83+
return ipfs.object.patch.setData(null, filePath)
84+
.then(
85+
() => expect.fail('should have returned an error for invalid argument'),
86+
(err) => expect(err).to.be.an.instanceof(Error)
87+
)
88+
})
7189
})
7290
}

src/object/stat.js

+16
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,21 @@ module.exports = (createCommon, options) => {
214214
})
215215
})
216216
})
217+
218+
it('returns error for request without argument', () => {
219+
return ipfs.object.stat(null)
220+
.then(
221+
() => expect.fail('should have returned an error for invalid argument'),
222+
(err) => expect(err).to.be.an.instanceof(Error)
223+
)
224+
})
225+
226+
it('returns error for request with invalid argument', () => {
227+
return ipfs.object.stat('invalid', { enc: 'base58' })
228+
.then(
229+
() => expect.fail('should have returned an error for invalid argument'),
230+
(err) => expect(err).to.be.an.instanceof(Error)
231+
)
232+
})
217233
})
218234
}

0 commit comments

Comments
 (0)