converted get stream to use knox, test to see if it is more robust

This commit is contained in:
Henry Oswald 2014-02-19 20:56:45 +00:00
parent 3f54688ec8
commit fada5ecaf4
2 changed files with 24 additions and 18 deletions

View file

@ -9,7 +9,6 @@ path = require("path")
LocalFileWriter = require("./LocalFileWriter") LocalFileWriter = require("./LocalFileWriter")
_ = require("underscore") _ = require("underscore")
thirtySeconds = 30 * 1000 thirtySeconds = 30 * 1000
buildDefaultOptions = (bucketName, method, key)-> buildDefaultOptions = (bucketName, method, key)->
@ -58,13 +57,19 @@ module.exports =
return callback(err) return callback(err)
@sendFileToS3 bucketName, key, fsPath, callback @sendFileToS3 bucketName, key, fsPath, callback
getFileStream: (bucketName, key, callback)-> getFileStream: (bucketName, key, callback = (err, res)->)->
logger.log bucketName:bucketName, key:key, "getting file from s3" logger.log bucketName:bucketName, key:key, "getting file from s3"
options = buildDefaultOptions(bucketName, "get", key) s3Client = knox.createClient
readStream = request(options) key: settings.s3.key
readStream.on "error", (err)-> secret: settings.s3.secret
bucket: bucketName
s3Stream = s3Client.get(key)
s3Stream.end()
s3Stream.on 'response', (res) ->
callback null, res
s3Stream.on 'error', (err) ->
logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3" logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3"
callback null, readStream callback err
copyFile: (bucketName, sourceKey, destKey, callback)-> copyFile: (bucketName, sourceKey, destKey, callback)->
logger.log bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "copying file in s3" logger.log bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "copying file in s3"

View file

@ -20,6 +20,7 @@ describe "s3WrapperTests", ->
copyFile:sinon.stub() copyFile:sinon.stub()
list: sinon.stub() list: sinon.stub()
deleteMultiple: sinon.stub() deleteMultiple: sinon.stub()
get: sinon.stub()
@knox = @knox =
createClient: sinon.stub().returns(@stubbedKnoxClient) createClient: sinon.stub().returns(@stubbedKnoxClient)
@LocalFileWriter = @LocalFileWriter =
@ -36,18 +37,18 @@ describe "s3WrapperTests", ->
@bucketName = "my-bucket" @bucketName = "my-bucket"
@error = "my errror" @error = "my errror"
describe "Pipe to dest", -> describe "getFileStream", ->
beforeEach ->
it "should use correct options", (done)->
stubbedReadStream = {on:->}
dest = {my:"object"}
@request = (opts)=>
return stubbedReadStream
@requires["request"] = @request
@s3Wrapper = SandboxedModule.require modulePath, requires: @requires @s3Wrapper = SandboxedModule.require modulePath, requires: @requires
@s3Wrapper.getFileStream @bucketName, @key, (err, readStream)->
readStream.should.equal stubbedReadStream
it "should use correct key", (done)->
@stubbedKnoxClient.get.returns(
on:->
end:->
)
@s3Wrapper.getFileStream @bucketName, @key, @fsPath, (err)=>
@stubbedKnoxClient.get.calledWith(@key).should.equal true
done() done()
describe "sendFileToS3", -> describe "sendFileToS3", ->