diff --git a/services/filestore/app/coffee/FSPersistorManager.coffee b/services/filestore/app/coffee/FSPersistorManager.coffee index 9b2b04dfe6..2ade1f3a5b 100644 --- a/services/filestore/app/coffee/FSPersistorManager.coffee +++ b/services/filestore/app/coffee/FSPersistorManager.coffee @@ -40,7 +40,7 @@ module.exports = if err.code == 'ENOENT' callback new Errors.NotFoundError(err.message), null else - callback err + callback err, null sourceStream.on 'readable', () -> # This can be called multiple times, but the callback wrapper # ensures the callback is only called once diff --git a/services/filestore/test/unit/coffee/FSPersistorManagerTests.coffee b/services/filestore/test/unit/coffee/FSPersistorManagerTests.coffee index 1668b0ff9d..75a4376b8c 100644 --- a/services/filestore/test/unit/coffee/FSPersistorManagerTests.coffee +++ b/services/filestore/test/unit/coffee/FSPersistorManagerTests.coffee @@ -29,6 +29,8 @@ describe "FSPersistorManagerTests", -> err:-> "response":response "rimraf":@Rimraf + "./Errors": @Errors = + NotFoundError: sinon.stub() @location = "/tmp" @name1 = "530f2407e7ef165704000007/530f838b46d9a9e859000008" @name1Filtered ="530f2407e7ef165704000007_530f838b46d9a9e859000008" @@ -89,6 +91,42 @@ describe "FSPersistorManagerTests", -> @Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}", @opts).should.equal true done() + describe "error conditions", -> + + beforeEach -> + @fakeCode = 'ENOENT' + @Fs.createReadStream.returns( + on: (key, callback) => + err = new Error() + err.code = @fakeCode + callback(err, null) + ) + + describe "when the file does not exist", -> + + beforeEach -> + @fakeCode = 'ENOENT' + + it "should give a NotFoundError", (done) -> + @FSPersistorManager.getFileStream @location, @name1, @opts, (err,res)=> + expect(res).to.equal null + expect(err).to.not.equal null + expect(err instanceof @Errors.NotFoundError).to.equal true + done() + + describe "when some other error happens", -> + + beforeEach -> + @fakeCode = 'SOMETHINGHORRIBLE' + + it "should give an Error", (done) -> + @FSPersistorManager.getFileStream @location, @name1, @opts, (err,res)=> + expect(res).to.equal null + expect(err).to.not.equal null + expect(err instanceof Error).to.equal true + done() + + describe "copyFile", -> beforeEach -> @@ -170,5 +208,3 @@ describe "FSPersistorManagerTests", -> @FSPersistorManager.checkIfFileExists @location, @name1, (err,exists) => exists.should.be.false done() - -