From 13ab7b5ca1a217d05ced890950e6a364b70a04f6 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Thu, 2 Apr 2020 16:49:45 +0100 Subject: [PATCH] Fix unit tests for pipeline changes --- .../test/unit/js/GcsPersistorTests.js | 22 +++++++------- .../test/unit/js/S3PersistorTests.js | 30 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/services/filestore/test/unit/js/GcsPersistorTests.js b/services/filestore/test/unit/js/GcsPersistorTests.js index cc13c45ce7..3c386e5002 100644 --- a/services/filestore/test/unit/js/GcsPersistorTests.js +++ b/services/filestore/test/unit/js/GcsPersistorTests.js @@ -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) { diff --git a/services/filestore/test/unit/js/S3PersistorTests.js b/services/filestore/test/unit/js/S3PersistorTests.js index 565e3e0bc9..c236de25ef 100644 --- a/services/filestore/test/unit/js/S3PersistorTests.js +++ b/services/filestore/test/unit/js/S3PersistorTests.js @@ -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) ) })