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

Commit

Permalink
test: add more tests for error checks
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
jacobheun committed Sep 19, 2018
1 parent fb2893c commit d5bce30
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ describe('S3Datastore', () => {
done()
})
})
it('should return a standard error when the put fails', (done) => {
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const store = new S3Store('.ipfs/datastore', { s3 })

standin.replace(s3, 'upload', function (stand, params, callback) {
expect(params.Key).to.equal('.ipfs/datastore/z/key')
stand.restore()
callback(new Error('bad things happened'))
})

store.put(new Key('/z/key'), Buffer.from('test data'), (err) => {
expect(err.code).to.equal('ERR_DB_WRITE_FAILED')
done()
})
})
})

describe('get', () => {
Expand All @@ -114,6 +129,41 @@ describe('S3Datastore', () => {

store.get(new Key('/z/key'), done)
})
it('should return a standard not found error code if the key isnt found', (done) => {
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const store = new S3Store('.ipfs/datastore', { s3 })

standin.replace(s3, 'getObject', function (stand, params, callback) {
expect(params.Key).to.equal('.ipfs/datastore/z/key')
stand.restore()
let error = new Error('not found')
error.statusCode = 404
callback(error)
})

store.get(new Key('/z/key'), (err) => {
expect(err.code).to.equal('ERR_NOT_FOUND')
done()
})
})
})

describe('delete', () => {
it('should return a standard delete error if deletion fails', (done) => {
const s3 = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const store = new S3Store('.ipfs/datastore', { s3 })

standin.replace(s3, 'deleteObject', function (stand, params, callback) {
expect(params.Key).to.equal('.ipfs/datastore/z/key')
stand.restore()
callback(new Error('bad things'))
})

store.delete(new Key('/z/key'), (err) => {
expect(err.code).to.equal('ERR_DB_DELETE_FAILED')
done()
})
})
})

describe('interface-datastore', () => {
Expand Down

0 comments on commit d5bce30

Please sign in to comment.