From fada5ecaf4aa2cecf68018b1750a5a1fbb2b3bbc Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 19 Feb 2014 20:56:45 +0000 Subject: [PATCH] converted get stream to use knox, test to see if it is more robust --- .../filestore/app/coffee/s3Wrapper.coffee | 17 ++++++++----- .../test/unit/coffee/s3WrapperTests.coffee | 25 ++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/services/filestore/app/coffee/s3Wrapper.coffee b/services/filestore/app/coffee/s3Wrapper.coffee index 2aea7945d8..f2eb067d39 100644 --- a/services/filestore/app/coffee/s3Wrapper.coffee +++ b/services/filestore/app/coffee/s3Wrapper.coffee @@ -8,7 +8,6 @@ knox = require("knox") path = require("path") LocalFileWriter = require("./LocalFileWriter") _ = require("underscore") - thirtySeconds = 30 * 1000 @@ -58,13 +57,19 @@ module.exports = return callback(err) @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" - options = buildDefaultOptions(bucketName, "get", key) - readStream = request(options) - readStream.on "error", (err)-> + s3Client = knox.createClient + key: settings.s3.key + 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" - callback null, readStream + callback err copyFile: (bucketName, sourceKey, destKey, callback)-> logger.log bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "copying file in s3" diff --git a/services/filestore/test/unit/coffee/s3WrapperTests.coffee b/services/filestore/test/unit/coffee/s3WrapperTests.coffee index 3de9c92dba..42023fea29 100644 --- a/services/filestore/test/unit/coffee/s3WrapperTests.coffee +++ b/services/filestore/test/unit/coffee/s3WrapperTests.coffee @@ -20,6 +20,7 @@ describe "s3WrapperTests", -> copyFile:sinon.stub() list: sinon.stub() deleteMultiple: sinon.stub() + get: sinon.stub() @knox = createClient: sinon.stub().returns(@stubbedKnoxClient) @LocalFileWriter = @@ -36,19 +37,19 @@ describe "s3WrapperTests", -> @bucketName = "my-bucket" @error = "my errror" - describe "Pipe to dest", -> - - it "should use correct options", (done)-> - - stubbedReadStream = {on:->} - dest = {my:"object"} - @request = (opts)=> - return stubbedReadStream - @requires["request"] = @request + describe "getFileStream", -> + beforeEach -> @s3Wrapper = SandboxedModule.require modulePath, requires: @requires - @s3Wrapper.getFileStream @bucketName, @key, (err, readStream)-> - readStream.should.equal stubbedReadStream - done() + + + 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() describe "sendFileToS3", ->