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

Commit

Permalink
Updated _fetch() to shut the source down and clear its properties if …
Browse files Browse the repository at this point in the history
…S3.getObject returns a NoSuchKey error. Added tests. Resolves #123.
  • Loading branch information
davepgreene committed Apr 14, 2016
1 parent 3ae39af commit 1d93af4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/source/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class S3 extends EventEmitter {
return callback(null, false);
}
if (err.code === 'NoSuchKey') {
return callback(null, false);
this.shutdown();
return callback(null, {properties: {}});
}

return callback(err);
Expand Down
24 changes: 22 additions & 2 deletions test/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,41 @@ describe('S3 source plugin', () => {
s3WithNoSuchKeyError = new S3({bucket: DEFAULT_BUCKET, path: 'foo.json'});
});

it('doesn\'t do anything if getRequest returns a NoSuchKey error', (done) => {
it('shuts down the source if getRequest returns a NoSuchKey error', (done) => {
const errorSpy = sinon.spy();
const updateSpy = sinon.spy();

shutdownSpy = sinon.spy();

s3WithNoSuchKeyError.on('error', errorSpy);
s3WithNoSuchKeyError.on('update', updateSpy);
s3WithNoSuchKeyError.on('shutdown', shutdownSpy);

s3WithNoSuchKeyError.on('shutdown', () => {
errorSpy.should.not.be.called();
updateSpy.should.not.be.called();
shutdownSpy.should.be.called();
s3WithNoSuchKeyError.properties.should.be.empty();
done();
});

s3WithNoSuchKeyError.initialize();
s3WithNoSuchKeyError.properties = {foo: 'bar'};
});

it('clears cached properties if getRequest returns a NoSuchKey error', (done) => {
S3 = s3Stub({
getObject: sinon.stub().callsArgWith(1, {code: 'NoSuchKey'}, null)
});

s3WithNoSuchKeyError = new S3({bucket: DEFAULT_BUCKET, path: 'foo.json'});
s3WithNoSuchKeyError.on('shutdown', () => {
s3WithNoSuchKeyError.properties.should.be.empty();
done();
});

s3WithNoSuchKeyError.initialize();
s3WithNoSuchKeyError.shutdown();
s3WithNoSuchKeyError.properties = {foo: 'bar'};
});

before(() => {
Expand Down

0 comments on commit 1d93af4

Please sign in to comment.