fix up mocha migration tests

This commit is contained in:
Henry Oswald 2018-05-21 11:02:53 +01:00
parent 768a4cc1ad
commit e3514e84cd
5 changed files with 14 additions and 22 deletions

View file

@ -4,9 +4,8 @@ logger = require("logger-sharelatex")
# assume s3 if none specified
settings?.filestore?.backend ||= "s3"
logger.log backend:settings.filestore.backend, "Loading backend"
module.exports = switch settings.filestore.backend
logger.log backend:settings?.filestore?.backend, "Loading backend"
module.exports = switch settings?.filestore?.backend
when "aws-sdk"
require "./AWSSDKPersistorManager"
when "s3"

View file

@ -77,7 +77,7 @@ module.exports =
if res.statusCode == 404
logger.log bucketName:bucketName, key:key, "file not found in s3"
return callback new Errors.NotFoundError("File not found in S3: #{bucketName}:#{key}"), null
if res.statusCode not in [200, 206]
else if res.statusCode not in [200, 206]
logger.log bucketName:bucketName, key:key, "error getting file from s3: #{res.statusCode}"
return callback new Error("Got non-200 response from S3: #{res.statusCode}"), null
callback null, res

View file

@ -33,8 +33,6 @@ describe "FSPersistorManagerTests", ->
err:->
"response":response
"rimraf":@Rimraf
"./Errors": @Errors =
NotFoundError: sinon.stub()
@location = "/tmp"
@name1 = "530f2407e7ef165704000007/530f838b46d9a9e859000008"
@name1Filtered ="530f2407e7ef165704000007_530f838b46d9a9e859000008"
@ -102,6 +100,7 @@ describe "FSPersistorManagerTests", ->
@Fs.createReadStream.returns(
on: (key, callback) =>
err = new Error()
err.message = "this is from a test"
err.code = @fakeCode
callback(err, null)
)
@ -115,7 +114,7 @@ describe "FSPersistorManagerTests", ->
@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
expect(err.name == "NotFoundError").to.equal true
done()
describe "when some other error happens", ->

View file

@ -66,7 +66,7 @@ describe "PersistorManagerTests", ->
describe "test unspecified mixins", ->
it "should load s3 when no wrapper specified", (done) ->
@settings =
@settings = {filestore:{}}
@requires =
"./S3PersistorManager": @S3PersistorManager
"settings-sharelatex": @settings

View file

@ -35,8 +35,6 @@ describe "S3PersistorManagerTests", ->
"logger-sharelatex":
log:->
err:->
"./Errors": @Errors =
NotFoundError: sinon.stub()
@key = "my/key"
@bucketName = "my-bucket"
@error = "my errror"
@ -84,35 +82,31 @@ describe "S3PersistorManagerTests", ->
describe "when the file doesn't exist", ->
beforeEach ->
@fakeResponse =
statusCode: 404
@bucketName = "mybucket"
@key = "somekey"
@fakeResponse.statusCode = 404
it "should produce a NotFoundError", (done) ->
@S3PersistorManager.getFileStream @bucketName, @key, @opts, (err, stream)=> # empty callback
expect(stream).to.equal null
expect(err).to.not.equal null
expect(err instanceof @Errors.NotFoundError).to.equal true
expect(err.name == "NotFoundError").to.equal true
done()
it "should have bucket and key in the Error message", (done) ->
@S3PersistorManager.getFileStream @bucketName, @key, @opts, (err, stream)=> # empty callback
error_message = @Errors.NotFoundError.lastCall.args[0]
expect(error_message).to.not.equal null
error_message.should.match(new RegExp(".*#{@bucketName}.*"))
error_message.should.match(new RegExp(".*#{@key}.*"))
expect(err.message).to.not.equal null
err.message.should.match(new RegExp(".*#{@bucketName}.*"))
err.message.should.match(new RegExp(".*#{@key}.*"))
done()
describe "when the S3 service produces an error", ->
beforeEach ->
@fakeResponse =
statusCode: 500
it "should produce an error", (done) ->
@S3PersistorManager.getFileStream @bucketName, @key, @opts, (err, stream)=> # empty callback
expect(stream).to.equal null
expect(err).to.not.equal null
expect(err instanceof Error).to.equal true
@Errors.NotFoundError.called.should.equal false
done()
describe "sendFile", ->