add unit tests

This commit is contained in:
Henrique Santos 2016-03-13 20:45:48 -03:00
parent 0bb12f32fa
commit ffaac4c81b
5 changed files with 67 additions and 13 deletions

View file

@ -251,7 +251,22 @@ describe "AWSSDKPersistorManager", ->
describe "directorySize", ->
it "should list the directory content using s3.listObjects", (done) ->
done()
@s3.listObjects.callsArgWith 1, null, Contents: []
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err) =>
expect(err).to.not.be.ok
expect(@s3.listObjects.calledOnce, "called only once").to.be.true
expect((@s3.listObjects.calledWith Bucket: @bucketName, Prefix: @key),
"called with correct arguments").to.be.true
done()
it "should sum directory files size", (done) ->
done()
it "should dispatch the error from s3.listObjects", (done) ->
@s3.listObjects.callsArgWith 1, @error
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err) =>
expect(err).to.equal @error
done()
it "should sum directory files sizes", (done) ->
@s3.listObjects.callsArgWith 1, null, Contents: [ { Size: 1024 }, { Size: 2048 }]
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err, size) =>
expect(size).to.equal 3072
done()

View file

@ -18,6 +18,10 @@ describe "FSPersistorManagerTests", ->
unlink:sinon.stub()
rmdir:sinon.stub()
exists:sinon.stub()
readdir:sinon.stub()
openSync:sinon.stub()
fstatSync:sinon.stub()
closeSync:sinon.stub()
@Rimraf = sinon.stub()
@LocalFileWriter =
writeStream: sinon.stub()
@ -211,5 +215,15 @@ describe "FSPersistorManagerTests", ->
describe "directorySize", ->
it "should propogate the error", (done) ->
@Fs.readdir.callsArgWith(1, @error)
@FSPersistorManager.directorySize @location, @name1, (err, totalsize) =>
err.should.equal @error
done()
it "should sum directory files size", (done) ->
done()
@Fs.readdir.callsArgWith(1, null, [ {'file1'}, {'file2'} ])
@Fs.fstatSync.returns({size : 1024})
@FSPersistorManager.directorySize @location, @name1, (err, totalsize) =>
expect(totalsize).to.equal 2048
done()

View file

@ -22,6 +22,7 @@ describe "FileController", ->
getFile: sinon.stub()
deleteFile: sinon.stub()
insertFile: sinon.stub()
getDirectorySize: sinon.stub()
@LocalFileWriter = {}
@controller = SandboxedModule.require modulePath, requires:
"./LocalFileWriter":@LocalFileWriter
@ -153,7 +154,17 @@ describe "FileController", ->
expect(result).to.equal null
done()
describe "directorySize", ->
describe "directorySize", ->
it "should call the file handler the directory size", (done) ->
done()
it "should return total directory size bytes", (done) ->
@FileHandler.getDirectorySize.callsArgWith(2, null, 1024)
@controller.directorySize @req, json:(result)=>
expect(result['total bytes']).to.equal 1024
done()
it "should send a 500 if there was an error", (done)->
@FileHandler.getDirectorySize.callsArgWith(2, "error")
@res.send = (code)->
code.should.equal 500
done()
@controller.directorySize @req, @res

View file

@ -20,6 +20,7 @@ describe "FileHandler", ->
deleteDirectory: sinon.stub()
sendStream: sinon.stub()
insertFile: sinon.stub()
directorySize: sinon.stub()
@LocalFileWriter =
writeStream: sinon.stub()
deleteFile: sinon.stub()
@ -193,7 +194,12 @@ describe "FileHandler", ->
@LocalFileWriter.deleteFile.calledWith(@stubbedPath).should.equal true
done()
describe "directorySize", ->
describe "getDirectorySize", ->
it "should call the filestore manager to get directory size", (done) ->
done()
beforeEach ->
@PersistorManager.directorySize.callsArgWith(2)
it "should call the filestore manager to get directory size", (done)->
@handler.getDirectorySize @bucket, @key, =>
@PersistorManager.directorySize.calledWith(@bucket, @key).should.equal true
done()

View file

@ -257,7 +257,15 @@ describe "S3PersistorManagerTests", ->
err.should.equal @error
done()
describe "directorySize", ->
describe "directorySize", ->
it "should sum directory files size", (done) ->
done()
beforeEach ->
@S3PersistorManager = SandboxedModule.require modulePath, requires: @requires
it "should sum directory files size", (done) ->
data =
Contents: [ {Size: 1024}, {Size: 2048} ]
@stubbedKnoxClient.list.callsArgWith(1, null, data)
@S3PersistorManager.directorySize @bucketName, @key, (err, totalSize)=>
totalSize.should.equal 3072
done()