diff --git a/test/index.spec.js b/test/index.spec.js index a61dfb9..3b84b82 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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', () => { @@ -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', () => {