Pass the start and end options down to fs.createReadStream, and test for same.

This commit is contained in:
Shane Kilkelly 2015-08-27 16:12:11 +01:00
parent 57aedefdd3
commit d88736e3b5
2 changed files with 18 additions and 5 deletions

View file

@ -33,7 +33,7 @@ module.exports =
_callback = () -> _callback = () ->
filteredName = filterName name filteredName = filterName name
logger.log location:location, name:filteredName, "getting file" logger.log location:location, name:filteredName, "getting file"
sourceStream = fs.createReadStream "#{location}/#{filteredName}" sourceStream = fs.createReadStream "#{location}/#{filteredName}", opts
sourceStream.on 'error', (err) -> sourceStream.on 'error', (err) ->
logger.err err:err, location:location, name:name, "Error reading from file" logger.err err:err, location:location, name:name, "Error reading from file"
if err.code = 'ENOENT' if err.code = 'ENOENT'

View file

@ -69,14 +69,27 @@ describe "FSPersistorManagerTests", ->
done() done()
describe "getFileStream", -> describe "getFileStream", ->
beforeEach ->
@opts = {}
it "should use correct file location", (done) -> it "should use correct file location", (done) ->
@Fs.createReadStream.returns( @Fs.createReadStream.returns({on: ->})
on:-> @FSPersistorManager.getFileStream @location, @name1, @opts, (err,res) =>
)
@FSPersistorManager.getFileStream @location, @name1, (err,res)=>
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true @Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
done() done()
describe "with start and end options", ->
beforeEach ->
@opts = {start: 0, end: 8}
it 'should pass the options to createReadStream', (done) ->
@Fs.createReadStream.returns({on: ->})
@FSPersistorManager.getFileStream @location, @name1, @opts, (err,res)=>
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}", @opts).should.equal true
done()
describe "copyFile", -> describe "copyFile", ->
beforeEach -> beforeEach ->
@ReadStream= @ReadStream=