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

Commit e7893b5

Browse files
committed
test: add more tests for error checks
License: MIT Signed-off-by: Jacob Heun <[email protected]>
1 parent fb2893c commit e7893b5

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/index.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ describe('S3Datastore', () => {
9999
done()
100100
})
101101
})
102+
it('should return a standard error when the put fails', (done) => {
103+
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
104+
const store = new S3Store('.ipfs/datastore', { s3 })
105+
106+
standin.replace(s3, 'upload', function (stand, params, callback) {
107+
expect(params.Key).to.equal('.ipfs/datastore/z/key')
108+
stand.restore()
109+
callback(new Error('bad things happened'))
110+
})
111+
112+
store.put(new Key('/z/key'), Buffer.from('test data'), (err) => {
113+
expect(err.code).to.equal('ERR_DB_WRITE_FAILED')
114+
done()
115+
})
116+
})
102117
})
103118

104119
describe('get', () => {
@@ -114,6 +129,58 @@ describe('S3Datastore', () => {
114129

115130
store.get(new Key('/z/key'), done)
116131
})
132+
it('should return a standard not found error code if the key isnt found', (done) => {
133+
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
134+
const store = new S3Store('.ipfs/datastore', { s3 })
135+
136+
standin.replace(s3, 'getObject', function (stand, params, callback) {
137+
expect(params.Key).to.equal('.ipfs/datastore/z/key')
138+
stand.restore()
139+
let error = new Error('not found')
140+
error.statusCode = 404
141+
callback(error)
142+
})
143+
144+
store.get(new Key('/z/key'), (err) => {
145+
expect(err.code).to.equal('ERR_NOT_FOUND')
146+
done()
147+
})
148+
})
149+
})
150+
151+
describe('delete', () => {
152+
it('should return a standard delete error if deletion fails', (done) => {
153+
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
154+
const store = new S3Store('.ipfs/datastore', { s3 })
155+
156+
standin.replace(s3, 'deleteObject', function (stand, params, callback) {
157+
expect(params.Key).to.equal('.ipfs/datastore/z/key')
158+
stand.restore()
159+
callback(new Error('bad things'))
160+
})
161+
162+
store.delete(new Key('/z/key'), (err) => {
163+
expect(err.code).to.equal('ERR_DB_DELETE_FAILED')
164+
done()
165+
})
166+
})
167+
})
168+
169+
describe('open', () => {
170+
it('should return a standard open error if the head request fails with an unknown error', (done) => {
171+
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
172+
const store = new S3Store('.ipfs/datastore', { s3 })
173+
174+
standin.replace(s3, 'headObject', function (stand, _, callback) {
175+
stand.restore()
176+
callback(new Error('unknown'))
177+
})
178+
179+
store.open((err) => {
180+
expect(err.code).to.equal('ERR_DB_OPEN_FAILED')
181+
done()
182+
})
183+
})
117184
})
118185

119186
describe('interface-datastore', () => {

0 commit comments

Comments
 (0)