mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-16 19:51:59 +00:00
Fix unit tests for pipeline changes
This commit is contained in:
parent
114883a9e9
commit
13ab7b5ca1
2 changed files with 30 additions and 22 deletions
|
@ -61,12 +61,15 @@ describe('GcsPersistorTests', function() {
|
|||
|
||||
ReadStream = {
|
||||
pipe: sinon.stub().returns('readStream'),
|
||||
on: sinon
|
||||
.stub()
|
||||
.withArgs('end')
|
||||
.yields(),
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub()
|
||||
}
|
||||
ReadStream.on.withArgs('end').yields()
|
||||
ReadStream.on.withArgs('pipe').yields({
|
||||
unpipe: sinon.stub(),
|
||||
resume: sinon.stub(),
|
||||
on: sinon.stub()
|
||||
})
|
||||
|
||||
Transform = class {
|
||||
on(event, callback) {
|
||||
|
@ -168,8 +171,7 @@ describe('GcsPersistorTests', function() {
|
|||
})
|
||||
|
||||
it('pipes the stream through the meter', function() {
|
||||
expect(Stream.pipeline).to.have.been.calledWith(
|
||||
ReadStream,
|
||||
expect(ReadStream.pipe).to.have.been.calledWith(
|
||||
sinon.match.instanceOf(Transform)
|
||||
)
|
||||
})
|
||||
|
@ -202,11 +204,11 @@ describe('GcsPersistorTests', function() {
|
|||
|
||||
beforeEach(async function() {
|
||||
Transform.prototype.on = sinon.stub()
|
||||
Stream.pipeline.yields(GcsNotFoundError)
|
||||
ReadStream.on.withArgs('error').yields(GcsNotFoundError)
|
||||
try {
|
||||
stream = await GcsPersistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
error = err
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -232,7 +234,7 @@ describe('GcsPersistorTests', function() {
|
|||
|
||||
beforeEach(async function() {
|
||||
Transform.prototype.on = sinon.stub()
|
||||
Stream.pipeline.yields(genericError)
|
||||
ReadStream.on.withArgs('error').yields(genericError)
|
||||
try {
|
||||
stream = await GcsPersistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
|
|
|
@ -87,11 +87,14 @@ describe('S3PersistorTests', function() {
|
|||
|
||||
ReadStream = {
|
||||
pipe: sinon.stub().returns('readStream'),
|
||||
on: sinon
|
||||
.stub()
|
||||
.withArgs('end')
|
||||
.yields()
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub()
|
||||
}
|
||||
ReadStream.on.withArgs('end').yields()
|
||||
ReadStream.on.withArgs('pipe').yields({
|
||||
unpipe: sinon.stub(),
|
||||
resume: sinon.stub()
|
||||
})
|
||||
|
||||
FileNotFoundError = new Error('File not found')
|
||||
FileNotFoundError.code = 'ENOENT'
|
||||
|
@ -111,6 +114,11 @@ describe('S3PersistorTests', function() {
|
|||
pipe: sinon.stub(),
|
||||
removeListener: sinon.stub()
|
||||
}
|
||||
S3ReadStream.on.withArgs('end').yields()
|
||||
S3ReadStream.on.withArgs('pipe').yields({
|
||||
unpipe: sinon.stub(),
|
||||
resume: sinon.stub()
|
||||
})
|
||||
S3Client = {
|
||||
getObject: sinon.stub().returns({
|
||||
createReadStream: sinon.stub().returns(S3ReadStream)
|
||||
|
@ -187,9 +195,8 @@ describe('S3PersistorTests', function() {
|
|||
})
|
||||
})
|
||||
|
||||
it('pipes the stream through the meter', function() {
|
||||
expect(Stream.pipeline).to.have.been.calledWith(
|
||||
S3ReadStream,
|
||||
it('pipes the stream through the meter', async function() {
|
||||
expect(S3ReadStream.pipe).to.have.been.calledWith(
|
||||
sinon.match.instanceOf(Transform)
|
||||
)
|
||||
})
|
||||
|
@ -292,7 +299,7 @@ describe('S3PersistorTests', function() {
|
|||
|
||||
beforeEach(async function() {
|
||||
Transform.prototype.on = sinon.stub()
|
||||
Stream.pipeline.yields(S3NotFoundError)
|
||||
S3ReadStream.on.withArgs('error').yields(S3NotFoundError)
|
||||
try {
|
||||
stream = await S3Persistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
|
@ -322,7 +329,7 @@ describe('S3PersistorTests', function() {
|
|||
|
||||
beforeEach(async function() {
|
||||
Transform.prototype.on = sinon.stub()
|
||||
Stream.pipeline.yields(S3AccessDeniedError)
|
||||
S3ReadStream.on.withArgs('error').yields(S3AccessDeniedError)
|
||||
try {
|
||||
stream = await S3Persistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
|
@ -352,7 +359,7 @@ describe('S3PersistorTests', function() {
|
|||
|
||||
beforeEach(async function() {
|
||||
Transform.prototype.on = sinon.stub()
|
||||
Stream.pipeline.yields(genericError)
|
||||
S3ReadStream.on.withArgs('error').yields(genericError)
|
||||
try {
|
||||
stream = await S3Persistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
|
@ -544,8 +551,7 @@ describe('S3PersistorTests', function() {
|
|||
})
|
||||
|
||||
it('should meter the download', function() {
|
||||
expect(Stream.pipeline).to.have.been.calledWith(
|
||||
S3ReadStream,
|
||||
expect(S3ReadStream.pipe).to.have.been.calledWith(
|
||||
sinon.match.instanceOf(Stream.Transform)
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue