diff --git a/bigquery/test/queries.test.js b/bigquery/test/queries.test.js index ab2d2188ee..1622696bfc 100644 --- a/bigquery/test/queries.test.js +++ b/bigquery/test/queries.test.js @@ -30,14 +30,14 @@ function getSample () { var jobMock = { id: jobId, - getQueryResults: sinon.stub().callsArgWith(0, null, natalityMock), - getMetadata: sinon.stub().callsArgWith(0, null, metadataMock) + getQueryResults: sinon.stub().yields(null, natalityMock), + getMetadata: sinon.stub().yields(null, metadataMock) }; var bigqueryMock = { job: sinon.stub().returns(jobMock), - startQuery: sinon.stub().callsArgWith(1, null, jobMock), - query: sinon.stub().callsArgWith(1, null, natalityMock) + startQuery: sinon.stub().yields(null, jobMock), + query: sinon.stub().yields(null, natalityMock) }; var BigQueryMock = sinon.stub().returns(bigqueryMock); @@ -67,35 +67,38 @@ describe('bigquery:query', function () { example.program.syncQuery(query, callback); - assert.ifError(callback.firstCall.args[0]); - assert(example.mocks.bigquery.query.called); - assert.deepEqual(callback.firstCall.args[1], example.mocks.natality); - assert(console.log.calledWith( - 'SyncQuery: found %d rows!', - callback.firstCall.args[1].length - )); + assert.equal(example.mocks.bigquery.query.calledOnce, true); + assert.deepEqual(example.mocks.bigquery.query.firstCall.args.slice(0, -1), [{ + query: query, + timeoutMs: 10000 + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, example.mocks.natality]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['SyncQuery: found %d rows!', example.mocks.natality.length]); }); it('should require a query', function () { + var error = new Error('"query" is required!'); var example = getSample(); var callback = sinon.stub(); example.program.syncQuery(null, callback); - assert.deepEqual(callback.firstCall.args[0], new Error('"query" is required!')); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle error', function () { var error = new Error('error'); var example = getSample(); var callback = sinon.stub(); - example.mocks.bigquery.query = sinon.stub().callsArgWith(1, error); + example.mocks.bigquery.query.yields(error); example.program.syncQuery(query, callback); - assert.deepEqual(callback.firstCall.args[0], error); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -108,34 +111,37 @@ describe('bigquery:query', function () { example.program.asyncQuery(query, callback); - assert.ifError(callback.firstCall.args[0]); - assert(example.mocks.bigquery.startQuery.called); - assert.deepEqual(callback.firstCall.args[1], example.mocks.job); - assert(console.log.calledWith( - 'AsyncQuery: submitted job %s!', example.jobId - )); + assert.equal(example.mocks.bigquery.startQuery.calledOnce, true); + assert.deepEqual(example.mocks.bigquery.startQuery.firstCall.args.slice(0, -1), [{ + query: query + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, example.mocks.job]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['AsyncQuery: submitted job %s!', example.jobId]); }); it('should require a query', function () { + var error = new Error('"query" is required!'); var example = getSample(); var callback = sinon.stub(); example.program.asyncQuery(null, callback); - assert.deepEqual(callback.firstCall.args[0], new Error('"query" is required!')); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle error', function () { var error = new Error('error'); var example = getSample(); var callback = sinon.stub(); - example.mocks.bigquery.startQuery = sinon.stub().callsArgWith(1, error); + example.mocks.bigquery.startQuery.yields(error); example.program.asyncQuery(query, callback); - assert.deepEqual(callback.firstCall.args[0], error); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -143,80 +149,70 @@ describe('bigquery:query', function () { it('should get the results of a job given its ID', function () { var example = getSample(); var callback = sinon.stub(); - example.mocks.bigquery.job = sinon.stub().returns(example.mocks.job); + example.mocks.bigquery.job.returns(example.mocks.job); example.program.asyncPoll(example.jobId, callback); - assert.ifError(callback.firstCall.args[0]); - assert(example.mocks.job.getQueryResults.called); - assert(console.log.calledWith( - 'AsyncQuery: polled job %s; got %d rows!', - example.jobId, - example.mocks.natality.length - )); + assert.equal(example.mocks.job.getMetadata.calledOnce, true); + assert.deepEqual(example.mocks.job.getMetadata.firstCall.args.slice(0, -1), []); + assert.equal(example.mocks.job.getQueryResults.calledOnce, true); + assert.deepEqual(example.mocks.job.getQueryResults.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, example.mocks.natality]); + assert.equal(console.log.calledTwice, true); + assert.deepEqual(console.log.firstCall.args, ['Job status: %s', example.mocks.metadata.status.state]); + assert.deepEqual(console.log.secondCall.args, ['AsyncQuery: polled job %s; got %d rows!', example.jobId, example.mocks.natality.length]); }); - it('should report the status of a job', function () { + it('should error when job is not finished', function () { var example = getSample(); var callback = sinon.stub(); + var pendingState = { status: { state: 'PENDING' } }; + example.mocks.job.getMetadata.yields(null, pendingState); + example.program.asyncPoll(example.jobId, callback); - assert.ifError(callback.firstCall.args[0]); - assert(example.mocks.job.getMetadata.called); - assert(console.log.calledWith( - 'Job status: %s', - example.mocks.metadata.status.state - )); + assert.equal(example.mocks.job.getMetadata.calledOnce, true); + assert.deepEqual(example.mocks.job.getMetadata.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [new Error('Job %s is not done', example.jobId)]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Job status: %s', pendingState.status.state]); }); - it('should check whether a job is finished', function () { + it('should require a job ID', function () { var example = getSample(); var callback = sinon.stub(); - var pendingState = { status: { state: 'PENDING' } }; - example.mocks.job.getMetadata = sinon.stub().callsArgWith(0, null, pendingState); - - example.program.asyncPoll(example.jobId, callback); + example.program.asyncPoll(null, callback); - assert.deepEqual(callback.firstCall.args[0], Error('Job %s is not done', example.jobId)); - assert(console.log.calledWith('Job status: %s', pendingState.status.state)); - assert(example.mocks.job.getMetadata.called); - assert.equal(example.mocks.job.getQueryResults.called, false); + assert.deepEqual(callback.firstCall.args[0], Error('"jobId" is required!')); assert.equal(callback.firstCall.args[1], undefined); - - var doneState = { status: { state: 'DONE' } }; - example.mocks.job.getMetadata = sinon.stub().callsArgWith(0, null, doneState); - - example.program.asyncPoll(example.jobId, callback); - - assert.ifError(callback.secondCall.args[0]); - assert(console.log.calledWith('Job status: %s', doneState.status.state)); - assert(example.mocks.job.getMetadata.called); - assert(example.mocks.job.getQueryResults.called); - assert.equal(callback.secondCall.args[1], example.mocks.natality); }); - it('should require a job ID', function () { + it('should handle getMetadata error', function () { + var error = new Error('error'); var example = getSample(); var callback = sinon.stub(); + example.mocks.job.getMetadata.yields(error); - example.program.asyncPoll(null, callback); + example.program.asyncPoll(example.jobId, callback); - assert.deepEqual(callback.firstCall.args[0], Error('"jobId" is required!')); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle error', function () { var error = new Error('error'); var example = getSample(); var callback = sinon.stub(); - example.mocks.job.getQueryResults = sinon.stub().callsArgWith(0, error); + example.mocks.job.getQueryResults.yields(error); example.program.asyncPoll(example.jobId, callback); - assert.deepEqual(callback.firstCall.args[0], error); - assert.equal(callback.firstCall.args[1], undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/bigquery/test/tables.test.js b/bigquery/test/tables.test.js index 51ec1abbed..b77b172c3f 100644 --- a/bigquery/test/tables.test.js +++ b/bigquery/test/tables.test.js @@ -317,8 +317,8 @@ describe('bigquery:tables', function () { assert.equal(callback.calledOnce, true); assert.deepEqual(callback.firstCall.args, [null, sample.mocks.metadata]); assert.equal(console.log.calledTwice, true); - assert.equal(console.log.calledWith('Started job: %s', sample.mocks.job.id), true); - assert.equal(console.log.calledWith('Completed job: %s', sample.mocks.job.id), true); + assert.deepEqual(console.log.firstCall.args, ['Started job: %s', sample.mocks.job.id]); + assert.deepEqual(console.log.secondCall.args, ['Completed job: %s', sample.mocks.job.id]); }); it('should handle error', function () { @@ -363,11 +363,11 @@ describe('bigquery:tables', function () { var example = getSample(); var callback = sinon.stub(); example.mocks.table.export.yields(error); + example.program.exportTableToGCS({ format: format }, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.equal(callback.firstCall.args[0], error, 'callback received error'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -384,6 +384,7 @@ describe('bigquery:tables', function () { var callback = sinon.stub(); program.insertRowsAsStream(options, callback); + assert.equal(callback.calledOnce, true); assert.deepEqual(callback.firstCall.args, [null, errorList]); }); @@ -392,9 +393,10 @@ describe('bigquery:tables', function () { var example = getSample(); var callback = sinon.stub(); var error = new Error('error'); - example.mocks.table.insert = sinon.stub().yields(error); + example.mocks.table.insert.yields(error); example.program.insertRowsAsStream(options, callback); + assert.equal(callback.calledOnce, true); assert.deepEqual(callback.firstCall.args, [error]); }); @@ -402,9 +404,10 @@ describe('bigquery:tables', function () { it('should handle (per-row) insert errors', function () { var example = getSample(); var callback = sinon.stub(); - example.mocks.table.insert = sinon.stub().yields(null, errorList); + example.mocks.table.insert.yields(null, errorList); example.program.insertRowsAsStream(options, callback); + assert.equal(callback.calledOnce, true); assert.deepEqual(callback.firstCall.args, [null, errorList]); }); diff --git a/logging/test/logs.test.js b/logging/test/logs.test.js index e5b3246733..15b32a3ada 100644 --- a/logging/test/logs.test.js +++ b/logging/test/logs.test.js @@ -28,13 +28,13 @@ function getSample () { var entryMock = {}; var logMock = { entry: sinon.stub().returns(entryMock), - write: sinon.stub().callsArgWith(1, null, apiResponseMock), - delete: sinon.stub().callsArgWith(0, null, apiResponseMock), - getEntries: sinon.stub().callsArgWith(0, null, entriesMock) + write: sinon.stub().yields(null, apiResponseMock), + delete: sinon.stub().yields(null, apiResponseMock), + getEntries: sinon.stub().yields(null, entriesMock) }; var loggingMock = { log: sinon.stub().returns(logMock), - getEntries: sinon.stub().callsArgWith(1, null, entriesMock) + getEntries: sinon.stub().yields(null, entriesMock) }; var LoggingMock = sinon.stub().returns(loggingMock); @@ -62,27 +62,24 @@ describe('logging:entries', function () { sample.program.listLogEntries(logName, callback); - assert(sample.mocks.log.getEntries.calledOnce, 'method called once'); - assert.equal(sample.mocks.log.getEntries.firstCall.args.length, 1, 'method received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.entries, 'callback received result'); - assert(console.log.calledWith('Found %d entries!', sample.mocks.entries.length)); + assert.equal(sample.mocks.log.getEntries.calledOnce, true); + assert.deepEqual(sample.mocks.log.getEntries.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.entries]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d entries!', sample.mocks.entries.length]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.log.getEntries = sinon.stub().callsArgWith(0, error); + sample.mocks.log.getEntries = sinon.stub().yields(error); sample.program.listLogEntries(logName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -93,32 +90,28 @@ describe('logging:entries', function () { sample.program.listLogEntriesAdvanced(filter, limit, sort, callback); - assert(sample.mocks.logging.getEntries.calledOnce, 'method called once'); - assert.equal(sample.mocks.logging.getEntries.firstCall.args.length, 2, 'method received 2 arguments'); - assert.deepEqual(sample.mocks.logging.getEntries.firstCall.args[0], { + assert.equal(sample.mocks.logging.getEntries.calledOnce, true); + assert.deepEqual(sample.mocks.logging.getEntries.firstCall.args.slice(0, -1), [{ pageSize: limit, filter: filter, orderBy: sort - }, 'method received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.entries, 'callback received result'); - assert(console.log.calledWith('Found %d entries!', sample.mocks.entries.length)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.entries]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d entries!', sample.mocks.entries.length]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.logging.getEntries = sinon.stub().callsArgWith(1, error); + sample.mocks.logging.getEntries = sinon.stub().yields(error); sample.program.listLogEntriesAdvanced(null, null, null, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -129,27 +122,24 @@ describe('logging:entries', function () { sample.program.writeLogEntry(logName, callback); - assert(sample.mocks.log.write.calledOnce, 'method called once'); - assert.equal(sample.mocks.log.write.firstCall.args.length, 2, 'method received 2 arguments'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.apiResponse, 'callback received result'); - assert(console.log.calledWith('Wrote to %s', logName)); + assert.equal(sample.mocks.log.write.calledOnce, true); + assert.deepEqual(sample.mocks.log.write.firstCall.args.slice(0, -1), [[sample.mocks.log.entry(), sample.mocks.log.entry()]]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.apiResponse]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Wrote to %s', logName]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.log.write = sinon.stub().callsArgWith(1, error); + sample.mocks.log.write = sinon.stub().yields(error); sample.program.writeLogEntry(logName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -177,14 +167,12 @@ describe('logging:entries', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.log.write = sinon.stub().callsArgWith(1, error); + sample.mocks.log.write = sinon.stub().yields(error); sample.program.writeLogEntryAdvanced(logName, {}, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -208,14 +196,12 @@ describe('logging:entries', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.log.delete = sinon.stub().callsArgWith(0, error); + sample.mocks.log.delete = sinon.stub().yields(error); sample.program.deleteLog(logName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/logging/test/sinks.test.js b/logging/test/sinks.test.js index 1b4801cceb..508d5c4826 100644 --- a/logging/test/sinks.test.js +++ b/logging/test/sinks.test.js @@ -93,10 +93,8 @@ describe('logging:sinks', function () { sample.program.createSink(sinkName, bucketName, filter, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -124,10 +122,8 @@ describe('logging:sinks', function () { sample.program.getSinkMetadata(sinkName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -155,10 +151,8 @@ describe('logging:sinks', function () { sample.program.listSinks(callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -189,10 +183,8 @@ describe('logging:sinks', function () { sample.program.updateSink(sinkName, filter, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -220,10 +212,8 @@ describe('logging:sinks', function () { sample.program.deleteSink(sinkName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/storage/test/acl.test.js b/storage/test/acl.test.js index 9898da765b..12d2835c6f 100644 --- a/storage/test/acl.test.js +++ b/storage/test/acl.test.js @@ -23,21 +23,21 @@ function getSample () { var aclObjectMock = {}; var fileMock = { acl: { - add: sinon.stub().callsArgWith(1, null, aclObjectMock), - get: sinon.stub().callsArgWith(0, null, aclObjectMock), - delete: sinon.stub().callsArgWith(1, null, aclObjectMock) + add: sinon.stub().yields(null, aclObjectMock), + get: sinon.stub().yields(null, aclObjectMock), + delete: sinon.stub().yields(null, aclObjectMock) }, name: fileName }; var bucketMock = { acl: { - add: sinon.stub().callsArgWith(1, null, aclObjectMock), - get: sinon.stub().callsArgWith(0, null, aclObjectMock), - delete: sinon.stub().callsArgWith(1, null, aclObjectMock), + add: sinon.stub().yields(null, aclObjectMock), + get: sinon.stub().yields(null, aclObjectMock), + delete: sinon.stub().yields(null, aclObjectMock), default: { - add: sinon.stub().callsArgWith(1, null, aclObjectMock), - get: sinon.stub().callsArgWith(0, null, aclObjectMock), - delete: sinon.stub().callsArgWith(1, null, aclObjectMock) + add: sinon.stub().yields(null, aclObjectMock), + get: sinon.stub().yields(null, aclObjectMock), + delete: sinon.stub().yields(null, aclObjectMock) } }, file: sinon.stub().returns(fileMock), @@ -76,17 +76,15 @@ describe('storage:acl', function () { sample.program.addAccessControl(options, callback); - assert(sample.mocks.bucket.acl.add.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.add.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.add.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.add.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.add.firstCall.args.slice(0, -1), [{ entity: entity, role: role - }, 'add received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Added access controls to: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Added access controls to: gs://%s', bucketName, '']); }); it('should add "default" access controls to bucket', function () { @@ -101,17 +99,15 @@ describe('storage:acl', function () { sample.program.addAccessControl(options, callback); - assert(sample.mocks.bucket.acl.default.add.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.default.add.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.default.add.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.default.add.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.default.add.firstCall.args.slice(0, -1), [{ entity: entity, role: role - }, 'add received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Added access controls to: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Added access controls to: gs://%s', bucketName, '']); }); it('should add access controls to a file', function () { @@ -126,24 +122,22 @@ describe('storage:acl', function () { sample.program.addAccessControl(options, callback); - assert(sample.mocks.file.acl.add.calledOnce, 'add called once'); - assert.equal(sample.mocks.file.acl.add.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.file.acl.add.firstCall.args[0], { + assert.equal(sample.mocks.file.acl.add.calledOnce, true); + assert.deepEqual(sample.mocks.file.acl.add.firstCall.args.slice(0, -1), [{ entity: entity, role: role - }, 'add received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Added access controls to: gs://%s/%s', bucketName, fileName)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Added access controls to: gs://%s/%s', bucketName, fileName]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.bucket.acl.add = sinon.stub().callsArgWith(1, error); + sample.mocks.bucket.acl.add.yields(error); sample.program.addAccessControl({ bucket: bucketName, @@ -151,10 +145,8 @@ describe('storage:acl', function () { role: role }, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -168,13 +160,12 @@ describe('storage:acl', function () { sample.program.getAccessControl(options, callback); - assert(sample.mocks.bucket.acl.get.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.get.firstCall.args.length, 1, 'add received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Got access controls for: gs://%s', bucketName, '')); + assert.equal(sample.mocks.bucket.acl.get.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.get.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got access controls for: gs://%s', bucketName, '']); }); it('should get all "default" access controls for a bucket', function () { @@ -187,13 +178,12 @@ describe('storage:acl', function () { sample.program.getAccessControl(options, callback); - assert(sample.mocks.bucket.acl.default.get.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.default.get.firstCall.args.length, 1, 'add received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Got access controls for: gs://%s', bucketName, '')); + assert.equal(sample.mocks.bucket.acl.default.get.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.default.get.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got access controls for: gs://%s', bucketName, '']); }); it('should get an entity\'s access controls for a bucket', function () { @@ -203,20 +193,18 @@ describe('storage:acl', function () { bucket: bucketName, entity: entity }; - sample.mocks.bucket.acl.get.callsArgWith(1, null, sample.mocks.aclObject); + sample.mocks.bucket.acl.get.yields(null, sample.mocks.aclObject); sample.program.getAccessControl(options, callback); - assert(sample.mocks.bucket.acl.get.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.get.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.get.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.get.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.get.firstCall.args.slice(0, -1), [{ entity: entity - }, 'get received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Got access controls for: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got access controls for: gs://%s', bucketName, '']); }); it('should get an entity\'s "default" access controls for a bucket', function () { @@ -227,20 +215,18 @@ describe('storage:acl', function () { entity: entity, default: true }; - sample.mocks.bucket.acl.default.get.callsArgWith(1, null, sample.mocks.aclObject); + sample.mocks.bucket.acl.default.get.yields(null, sample.mocks.aclObject); sample.program.getAccessControl(options, callback); - assert(sample.mocks.bucket.acl.default.get.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.default.get.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.default.get.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.default.get.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.default.get.firstCall.args.slice(0, -1), [{ entity: entity - }, 'get received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Got access controls for: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got access controls for: gs://%s', bucketName, '']); }); it('should get access controls for a file', function () { @@ -253,13 +239,12 @@ describe('storage:acl', function () { sample.program.getAccessControl(options, callback); - assert(sample.mocks.file.acl.get.calledOnce, 'add called once'); - assert.equal(sample.mocks.file.acl.get.firstCall.args.length, 1, 'add received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Got access controls for: gs://%s/%s', bucketName, fileName)); + assert.equal(sample.mocks.file.acl.get.calledOnce, true); + assert.deepEqual(sample.mocks.file.acl.get.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.aclObject]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got access controls for: gs://%s/%s', bucketName, fileName]); }); it('should handle error', function () { @@ -269,14 +254,12 @@ describe('storage:acl', function () { var options = { bucket: bucketName }; - sample.mocks.bucket.acl.get = sinon.stub().callsArgWith(0, error); + sample.mocks.bucket.acl.get.yields(error); sample.program.getAccessControl(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -288,19 +271,18 @@ describe('storage:acl', function () { bucket: bucketName, entity: entity }; - sample.mocks.bucket.acl.delete.callsArgWith(1, null, sample.mocks.aclObject); + sample.mocks.bucket.acl.delete.yields(null, sample.mocks.aclObject); sample.program.deleteAccessControl(options, callback); - assert(sample.mocks.bucket.acl.delete.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.delete.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.delete.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.delete.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.delete.firstCall.args.slice(0, -1), [{ entity: entity - }, 'get received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Deleted access controls from: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Deleted access controls from: gs://%s', bucketName, '']); }); it('should delete an entity\'s "default" access controls from a bucket', function () { @@ -311,19 +293,18 @@ describe('storage:acl', function () { entity: entity, default: true }; - sample.mocks.bucket.acl.default.delete.callsArgWith(1, null, sample.mocks.aclObject); + sample.mocks.bucket.acl.default.delete.yields(null, sample.mocks.aclObject); sample.program.deleteAccessControl(options, callback); - assert(sample.mocks.bucket.acl.default.delete.calledOnce, 'add called once'); - assert.equal(sample.mocks.bucket.acl.default.delete.firstCall.args.length, 2, 'add received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.acl.default.delete.firstCall.args[0], { + assert.equal(sample.mocks.bucket.acl.default.delete.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.acl.default.delete.firstCall.args.slice(0, -1), [{ entity: entity - }, 'get received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Deleted access controls from: gs://%s', bucketName, '')); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Deleted access controls from: gs://%s', bucketName, '']); }); it('should delete access controls from a file', function () { @@ -337,12 +318,14 @@ describe('storage:acl', function () { sample.program.deleteAccessControl(options, callback); - assert(sample.mocks.file.acl.delete.calledOnce, 'add called once'); - assert.equal(sample.mocks.file.acl.delete.firstCall.args.length, 2, 'delete received 2 arguments'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Deleted access controls from: gs://%s/%s', bucketName, fileName)); + assert.equal(sample.mocks.file.acl.delete.calledOnce, true); + assert.deepEqual(sample.mocks.file.acl.delete.firstCall.args.slice(0, -1), [{ + entity: entity + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Deleted access controls from: gs://%s/%s', bucketName, fileName]); }); it('should handle error', function () { @@ -352,14 +335,12 @@ describe('storage:acl', function () { var options = { bucket: bucketName }; - sample.mocks.bucket.acl.delete = sinon.stub().callsArgWith(1, error); + sample.mocks.bucket.acl.delete.yields(error); sample.program.deleteAccessControl(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/storage/test/buckets.test.js b/storage/test/buckets.test.js index 11aae5c5e9..cfb2a2a5ce 100644 --- a/storage/test/buckets.test.js +++ b/storage/test/buckets.test.js @@ -24,11 +24,11 @@ function getSample () { } ]; var bucketMock = { - create: sinon.stub().callsArgWith(0, null, bucketsMock[0]), - delete: sinon.stub().callsArgWith(0, null) + create: sinon.stub().yields(null, bucketsMock[0]), + delete: sinon.stub().yields(null) }; var storageMock = { - getBuckets: sinon.stub().callsArgWith(0, null, bucketsMock, null, bucketsMock), + getBuckets: sinon.stub().yields(null, bucketsMock, null, bucketsMock), bucket: sinon.stub().returns(bucketMock) }; var StorageMock = sinon.stub().returns(storageMock); @@ -55,27 +55,24 @@ describe('storage:buckets', function () { sample.program.createBucket(bucketName, callback); - assert(sample.mocks.bucket.create.calledOnce, 'create called once'); - assert.equal(sample.mocks.bucket.create.firstCall.args.length, 1, 'create received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.buckets[0], 'callback received bucket'); - assert(console.log.calledWith('Created bucket: %s', bucketName)); + assert.equal(sample.mocks.bucket.create.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.create.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.buckets[0]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Created bucket: %s', bucketName]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.bucket.create = sinon.stub().callsArgWith(0, error); + sample.mocks.bucket.create.yields(error); sample.program.createBucket(bucketName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -86,27 +83,24 @@ describe('storage:buckets', function () { sample.program.listBuckets(callback); - assert(sample.mocks.storage.getBuckets.calledOnce, 'getBuckets called once'); - assert.equal(sample.mocks.storage.getBuckets.firstCall.args.length, 1, 'getBuckets received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.buckets, 'callback received buckets'); - assert(console.log.calledWith('Found %d bucket(s)!', sample.mocks.buckets.length)); + assert.equal(sample.mocks.storage.getBuckets.calledOnce, true); + assert.deepEqual(sample.mocks.storage.getBuckets.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.buckets]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d bucket(s)!', sample.mocks.buckets.length]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storage.getBuckets = sinon.stub().callsArgWith(0, error); + sample.mocks.storage.getBuckets.yields(error); sample.program.listBuckets(callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -117,28 +111,24 @@ describe('storage:buckets', function () { sample.program.deleteBucket(bucketName, callback); - assert(sample.mocks.bucket.delete.calledOnce, 'delete called once'); - assert.equal(sample.mocks.bucket.delete.firstCall.args.length, 1, 'delete received 1 argument'); - assert.equal(sample.mocks.storage.bucket.firstCall.args[0], bucketName); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.aclObject, 'callback received acl object'); - assert(console.log.calledWith('Deleted bucket: %s', bucketName)); + assert.equal(sample.mocks.bucket.delete.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.delete.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Deleted bucket: %s', bucketName]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.bucket.delete = sinon.stub().callsArgWith(0, error); + sample.mocks.bucket.delete.yields(error); sample.program.deleteBucket(bucketName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/storage/test/encryption.test.js b/storage/test/encryption.test.js index e4c87940fd..948378dfd2 100644 --- a/storage/test/encryption.test.js +++ b/storage/test/encryption.test.js @@ -26,17 +26,18 @@ function getSample () { } ]; var fileMock = { - download: sinon.stub().callsArgWith(1, null), + download: sinon.stub().yields(null), setEncryptionKey: sinon.stub() }; var bucketMock = { - upload: sinon.stub().callsArgWith(2, null, filesMock[0]), + upload: sinon.stub().yields(null, filesMock[0]), file: sinon.stub().returns(fileMock) }; var storageMock = { bucket: sinon.stub().returns(bucketMock) }; var StorageMock = sinon.stub().returns(storageMock); + return { program: proxyquire('../encryption', { '@google-cloud/storage': StorageMock, @@ -58,7 +59,8 @@ describe('storage:encryption', function () { var program = getSample().program; var key = program.generateEncryptionKey(); - assert(console.log.calledWith('Base 64 encoded encryption key: %s', key)); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Base 64 encoded encryption key: %s', key]); }); }); @@ -75,18 +77,15 @@ describe('storage:encryption', function () { sample.program.uploadEncryptedFile(options, callback); - assert(sample.mocks.bucket.upload.calledOnce, 'upload called once'); - assert.equal(sample.mocks.bucket.upload.firstCall.args.length, 3, 'upload received 3 arguments'); - assert.deepEqual(sample.mocks.bucket.upload.firstCall.args[0], fileName, 'upload received file name'); - assert.deepEqual(sample.mocks.bucket.upload.firstCall.args[1], { + assert.equal(sample.mocks.bucket.upload.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.upload.firstCall.args.slice(0, -1), [fileName, { destination: options.destFile, encryptionKey: new Buffer(options.key, 'base64') - }, 'upload received config'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files[0], 'callback received file'); - assert(console.log.calledWith('Uploaded gs://%s/%s', options.bucket, options.destFile)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files[0]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Uploaded gs://%s/%s', options.bucket, options.destFile]); }); it('should handle error', function () { @@ -99,14 +98,12 @@ describe('storage:encryption', function () { destFile: fileName, key: key }; - sample.mocks.bucket.upload = sinon.stub().callsArgWith(2, error); + sample.mocks.bucket.upload.yields(error); sample.program.uploadEncryptedFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -123,15 +120,14 @@ describe('storage:encryption', function () { sample.program.downloadEncryptedFile(options, callback); - assert(sample.mocks.file.download.calledOnce, 'download called once'); - assert.equal(sample.mocks.file.download.firstCall.args.length, 2, 'download received 2 arguments'); - assert.deepEqual(sample.mocks.file.download.firstCall.args[0], { + assert.equal(sample.mocks.file.download.calledOnce, true); + assert.deepEqual(sample.mocks.file.download.firstCall.args.slice(0, -1), [{ destination: options.destFile - }, 'download received config'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Downloaded gs://%s/%s to %s', options.bucket, options.srcFile, options.destFile)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Downloaded gs://%s/%s to %s', options.bucket, options.srcFile, options.destFile]); }); it('should handle error', function () { @@ -144,14 +140,12 @@ describe('storage:encryption', function () { destFile: fileName, key: key }; - sample.mocks.file.download = sinon.stub().callsArgWith(1, error); + sample.mocks.file.download.yields(error); sample.program.downloadEncryptedFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/storage/test/files.test.js b/storage/test/files.test.js index 81564b54cf..bd8288ce30 100644 --- a/storage/test/files.test.js +++ b/storage/test/files.test.js @@ -28,22 +28,23 @@ function getSample () { } ]; var fileMock = { - download: sinon.stub().callsArgWith(1, null), - getMetadata: sinon.stub().callsArgWith(0, null, { foo: 'bar' }), - makePublic: sinon.stub().callsArgWith(0, null), - delete: sinon.stub().callsArgWith(0, null), - move: sinon.stub().callsArgWith(1, null, filesMock[0]), - copy: sinon.stub().callsArgWith(1, null, filesMock[0]) + download: sinon.stub().yields(null), + getMetadata: sinon.stub().yields(null, { foo: 'bar' }), + makePublic: sinon.stub().yields(null), + delete: sinon.stub().yields(null), + move: sinon.stub().yields(null, filesMock[0]), + copy: sinon.stub().yields(null, filesMock[0]) }; var bucketMock = { - getFiles: sinon.stub().callsArgWith(0, null, filesMock, null, filesMock), + getFiles: sinon.stub().yields(null, filesMock), file: sinon.stub().returns(fileMock), - upload: sinon.stub().callsArgWith(1, null, filesMock[0]) + upload: sinon.stub().yields(null, filesMock[0]) }; var storageMock = { bucket: sinon.stub().returns(bucketMock) }; var StorageMock = sinon.stub().returns(storageMock); + return { program: proxyquire('../files', { '@google-cloud/storage': StorageMock, @@ -67,27 +68,24 @@ describe('storage:files', function () { sample.program.listFiles(bucketName, callback); - assert(sample.mocks.bucket.getFiles.calledOnce, 'getFiles called once'); - assert.equal(sample.mocks.bucket.getFiles.firstCall.args.length, 1, 'getFiles received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files, 'callback received files'); - assert(console.log.calledWith('Found %d file(s)!', sample.mocks.files.length)); + assert.equal(sample.mocks.bucket.getFiles.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.getFiles.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d file(s)!', sample.mocks.files.length]); }); it('should handle error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.bucket.getFiles = sinon.stub().callsArgWith(0, error); + sample.mocks.bucket.getFiles.yields(error); sample.program.listFiles(bucketName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -100,20 +98,17 @@ describe('storage:files', function () { bucket: bucketName, prefix: prefix }; - sample.mocks.bucket.getFiles = sinon.stub().callsArgWith(1, null, sample.mocks.files); sample.program.listFilesByPrefix(options, callback); - assert(sample.mocks.bucket.getFiles.calledOnce, 'getFiles called once'); - assert.equal(sample.mocks.bucket.getFiles.firstCall.args.length, 2, 'getFiles received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.getFiles.firstCall.args[0], { + assert.equal(sample.mocks.bucket.getFiles.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.getFiles.firstCall.args.slice(0, -1), [{ prefix: prefix - }, 'getFiles received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files, 'callback received files'); - assert(console.log.calledWith('Found %d file(s)!', sample.mocks.files.length)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d file(s)!', sample.mocks.files.length]); }); it('should list files with prefix and delimiter', function () { @@ -126,21 +121,18 @@ describe('storage:files', function () { prefix: prefix, delimiter: delimiter }; - sample.mocks.bucket.getFiles = sinon.stub().callsArgWith(1, null, sample.mocks.files); sample.program.listFilesByPrefix(options, callback); - assert(sample.mocks.bucket.getFiles.calledOnce, 'getFiles called once'); - assert.equal(sample.mocks.bucket.getFiles.firstCall.args.length, 2, 'getFiles received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.getFiles.firstCall.args[0], { + assert.equal(sample.mocks.bucket.getFiles.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.getFiles.firstCall.args.slice(0, -1), [{ prefix: prefix, delimiter: delimiter - }, 'getFiles received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files, 'callback received files'); - assert(console.log.calledWith('Found %d file(s)!', sample.mocks.files.length)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d file(s)!', sample.mocks.files.length]); }); it('should handle error', function () { @@ -152,14 +144,12 @@ describe('storage:files', function () { bucket: bucketName, prefix: prefix }; - sample.mocks.bucket.getFiles = sinon.stub().callsArgWith(1, error); + sample.mocks.bucket.getFiles.yields(error); sample.program.listFilesByPrefix(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -174,14 +164,12 @@ describe('storage:files', function () { sample.program.uploadFile(options, callback); - assert(sample.mocks.bucket.upload.calledOnce, 'upload called once'); - assert.equal(sample.mocks.bucket.upload.firstCall.args.length, 2, 'upload received 2 arguments'); - assert.deepEqual(sample.mocks.bucket.upload.firstCall.args[0], srcFileName, 'upload received file name'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files[0], 'callback received file'); - assert(console.log.calledWith('Uploaded gs://%s/%s', options.bucket, options.srcFile)); + assert.equal(sample.mocks.bucket.upload.calledOnce, true); + assert.deepEqual(sample.mocks.bucket.upload.firstCall.args.slice(0, -1), [srcFileName]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files[0]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Uploaded gs://%s/%s', options.bucket, options.srcFile]); }); it('should handle error', function () { @@ -192,14 +180,12 @@ describe('storage:files', function () { bucket: bucketName, srcFile: srcFileName }; - sample.mocks.bucket.upload = sinon.stub().callsArgWith(1, error); + sample.mocks.bucket.upload.yields(error); sample.program.uploadFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -215,15 +201,14 @@ describe('storage:files', function () { sample.program.downloadFile(options, callback); - assert(sample.mocks.file.download.calledOnce, 'download called once'); - assert.equal(sample.mocks.file.download.firstCall.args.length, 2, 'download received 2 arguments'); - assert.deepEqual(sample.mocks.file.download.firstCall.args[0], { + assert.equal(sample.mocks.file.download.calledOnce, true); + assert.deepEqual(sample.mocks.file.download.firstCall.args.slice(0, -1), [{ destination: options.destFile - }, 'download received file name'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Downloaded gs://%s/%s to %s', options.bucket, options.srcFile, options.destFile)); + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Downloaded gs://%s/%s to %s', options.bucket, options.srcFile, options.destFile]); }); it('should handle error', function () { @@ -235,14 +220,12 @@ describe('storage:files', function () { srcFile: srcFileName, destFile: destFileName }; - sample.mocks.file.download = sinon.stub().callsArgWith(1, error); + sample.mocks.file.download.yields(error); sample.program.downloadFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -257,12 +240,12 @@ describe('storage:files', function () { sample.program.deleteFile(options, callback); - assert(sample.mocks.file.delete.calledOnce, 'delete called once'); - assert.equal(sample.mocks.file.delete.firstCall.args.length, 1, 'delete received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Deleted gs://%s/%s', options.bucket, options.file)); + assert.equal(sample.mocks.file.delete.calledOnce, true); + assert.deepEqual(sample.mocks.file.delete.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Deleted gs://%s/%s', options.bucket, options.file]); }); it('should handle error', function () { @@ -273,14 +256,12 @@ describe('storage:files', function () { bucket: bucketName, file: srcFileName }; - sample.mocks.file.delete = sinon.stub().callsArgWith(0, error); + sample.mocks.file.delete.yields(error); sample.program.deleteFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -295,13 +276,12 @@ describe('storage:files', function () { sample.program.getMetadata(options, callback); - assert(sample.mocks.file.getMetadata.calledOnce, 'getMetadata called once'); - assert.equal(sample.mocks.file.getMetadata.firstCall.args.length, 1, 'getMetadata received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.firstCall.args[1], { foo: 'bar' }, 'callback received metadata'); - assert(console.log.calledWith('Got metadata for gs://%s/%s', options.bucket, options.file)); + assert.equal(sample.mocks.file.getMetadata.calledOnce, true); + assert.deepEqual(sample.mocks.file.getMetadata.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, { foo: 'bar' }]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Got metadata for gs://%s/%s', options.bucket, options.file]); }); it('should handle error', function () { @@ -312,14 +292,12 @@ describe('storage:files', function () { bucket: bucketName, file: srcFileName }; - sample.mocks.file.getMetadata = sinon.stub().callsArgWith(0, error); + sample.mocks.file.getMetadata.yields(error); sample.program.getMetadata(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -334,12 +312,12 @@ describe('storage:files', function () { sample.program.makePublic(options, callback); - assert(sample.mocks.file.makePublic.calledOnce, 'makePublic called once'); - assert.equal(sample.mocks.file.makePublic.firstCall.args.length, 1, 'makePublic received 1 argument'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert(console.log.calledWith('Made gs://%s/%s public!', options.bucket, options.file)); + assert.equal(sample.mocks.file.makePublic.calledOnce, true); + assert.deepEqual(sample.mocks.file.makePublic.firstCall.args.slice(0, -1), []); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Made gs://%s/%s public!', options.bucket, options.file]); }); it('should handle error', function () { @@ -350,14 +328,12 @@ describe('storage:files', function () { bucket: bucketName, file: srcFileName }; - sample.mocks.file.makePublic = sinon.stub().callsArgWith(0, error); + sample.mocks.file.makePublic.yields(error); sample.program.makePublic(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -373,14 +349,12 @@ describe('storage:files', function () { sample.program.moveFile(options, callback); - assert(sample.mocks.file.move.calledOnce, 'move called once'); - assert.equal(sample.mocks.file.move.firstCall.args.length, 2, 'move received 2 arguments'); - assert.deepEqual(sample.mocks.file.move.firstCall.args[0], options.destFile, 'move received options'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files[0], 'callback received file'); - assert(console.log.calledWith('Renamed gs://%s/%s to gs://%s/%s', options.bucket, options.srcFile, options.bucket, options.destFile)); + assert.equal(sample.mocks.file.move.calledOnce, true); + assert.deepEqual(sample.mocks.file.move.firstCall.args.slice(0, -1), [options.destFile]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files[0]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Renamed gs://%s/%s to gs://%s/%s', options.bucket, options.srcFile, options.bucket, options.destFile]); }); it('should handle error', function () { @@ -392,14 +366,12 @@ describe('storage:files', function () { srcFile: srcFileName, destFile: movedFileName }; - sample.mocks.file.move = sinon.stub().callsArgWith(1, error); + sample.mocks.file.move.yields(error); sample.program.moveFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -416,13 +388,12 @@ describe('storage:files', function () { sample.program.copyFile(options, callback); - assert(sample.mocks.file.copy.calledOnce, 'copy called once'); - assert.equal(sample.mocks.file.copy.firstCall.args.length, 2, 'copy received 2 arguments'); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.files[0], 'callback received file'); - assert(console.log.calledWith('Copied gs://%s/%s to gs://%s/%s', options.srcBucket, options.srcFile, options.destBucket, options.destFile)); + assert.equal(sample.mocks.file.copy.calledOnce, true); + assert.deepEqual(sample.mocks.file.copy.firstCall.args.slice(0, -1), [sample.mocks.storage.bucket(options.destBucket).file(options.destFile)]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.files[0]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Copied gs://%s/%s to gs://%s/%s', options.srcBucket, options.srcFile, options.destBucket, options.destFile]); }); it('should handle error', function () { @@ -435,14 +406,12 @@ describe('storage:files', function () { destFile: copiedFileName, destBucket: bucketName }; - sample.mocks.file.copy = sinon.stub().callsArgWith(1, error); + sample.mocks.file.copy.yields(error); sample.program.copyFile(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); diff --git a/storage/test/transfer.test.js b/storage/test/transfer.test.js index e8a89e165e..4870a8741a 100644 --- a/storage/test/transfer.test.js +++ b/storage/test/transfer.test.js @@ -26,22 +26,22 @@ function getSample () { var transferOperationMock = {}; var storagetransferMock = { transferJobs: { - create: sinon.stub().callsArgWith(1, null, transferJobMock), - get: sinon.stub().callsArgWith(1, null, transferJobMock), - patch: sinon.stub().callsArgWith(1, null, transferJobMock), - list: sinon.stub().callsArgWith(1, null, { transferJobs: [transferJobMock] }) + create: sinon.stub().yields(null, transferJobMock), + get: sinon.stub().yields(null, transferJobMock), + patch: sinon.stub().yields(null, transferJobMock), + list: sinon.stub().yields(null, { transferJobs: [transferJobMock] }) }, transferOperations: { - get: sinon.stub().callsArgWith(1, null, transferOperationMock), - pause: sinon.stub().callsArgWith(1, null, transferOperationMock), - resume: sinon.stub().callsArgWith(1, null, transferOperationMock), - list: sinon.stub().callsArgWith(1, null, { operations: [transferOperationMock] }) + get: sinon.stub().yields(null, transferOperationMock), + pause: sinon.stub().yields(null, transferOperationMock), + resume: sinon.stub().yields(null, transferOperationMock), + list: sinon.stub().yields(null, { operations: [transferOperationMock] }) } }; var googleapisMock = { storagetransfer: sinon.stub().returns(storagetransferMock), auth: { - getApplicationDefault: sinon.stub().callsArgWith(0, null, {}) + getApplicationDefault: sinon.stub().yields(null, {}) } }; @@ -77,50 +77,46 @@ describe('storage:transfer', function () { sample.program.createTransferJob(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); - assert.equal(sample.mocks.storagetransfer.transferJobs.create.firstCall.args[0].resource.description, undefined, 'description was not set'); - assert(console.log.calledWith('Created transfer job: %s', sample.mocks.transferJob.name)); + assert.equal(sample.mocks.storagetransfer.transferJobs.create.calledOnce, true); + assert.equal(sample.mocks.storagetransfer.transferJobs.create.firstCall.args[0].resource.description, undefined); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Created transfer job: %s', sample.mocks.transferJob.name]); options.description = description; sample.program.createTransferJob(options, callback); - assert(callback.calledTwice, 'callback called twice'); - assert.equal(callback.secondCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.secondCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.secondCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); - assert.equal(sample.mocks.storagetransfer.transferJobs.create.secondCall.args[0].resource.description, description, 'description was set'); - assert(console.log.calledWith('Created transfer job: %s', sample.mocks.transferJob.name)); + assert.equal(sample.mocks.storagetransfer.transferJobs.create.calledTwice, true); + assert.equal(sample.mocks.storagetransfer.transferJobs.create.secondCall.args[0].resource.description, description); + assert.equal(callback.calledTwice, true); + assert.deepEqual(callback.secondCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledTwice, true); + assert.deepEqual(console.log.secondCall.args, ['Created transfer job: %s', sample.mocks.transferJob.name]); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.createTransferJob({}, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle create error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferJobs.create.callsArgWith(1, error); + sample.mocks.storagetransfer.transferJobs.create.yields(error); sample.program.createTransferJob({}, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -131,39 +127,40 @@ describe('storage:transfer', function () { sample.program.getTransferJob(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); - assert(console.log.calledWith('Found transfer job: %s', sample.mocks.transferJob.name)); + assert.equal(sample.mocks.storagetransfer.transferJobs.get.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.get.firstCall.args.slice(0, -1), [{ + auth: {}, + projectId: process.env.GCLOUD_PROJECT, + jobName: jobName + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found transfer job: %s', sample.mocks.transferJob.name]); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.getTransferJob(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle get error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferJobs.get.callsArgWith(1, error); + sample.mocks.storagetransfer.transferJobs.get.yields(error); sample.program.getTransferJob(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -179,31 +176,69 @@ describe('storage:transfer', function () { sample.program.updateTransferJob(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.firstCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); + assert.equal(sample.mocks.storagetransfer.transferJobs.patch.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.patch.firstCall.args.slice(0, -1), [{ + auth: {}, + jobName: jobName, + resource: { + projectId: process.env.GCLOUD_PROJECT, + transferJob: { + name: jobName, + status: options.value + }, + updateTransferJobFieldMask: options.field + } + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Updated transfer job: %s', jobName]); options.field = 'description'; options.value = 'description'; sample.program.updateTransferJob(options, callback); - assert(callback.calledTwice, 'callback called twice'); - assert.equal(callback.secondCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.secondCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.secondCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); + assert.equal(sample.mocks.storagetransfer.transferJobs.patch.calledTwice, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.patch.secondCall.args.slice(0, -1), [{ + auth: {}, + jobName: jobName, + resource: { + projectId: process.env.GCLOUD_PROJECT, + transferJob: { + name: jobName, + description: options.value + }, + updateTransferJobFieldMask: options.field + } + }]); + assert.equal(callback.calledTwice, true); + assert.deepEqual(callback.secondCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledTwice, true); + assert.deepEqual(console.log.secondCall.args, ['Updated transfer job: %s', jobName]); options.field = 'transferSpec'; options.value = '{"foo":"bar"}'; sample.program.updateTransferJob(options, callback); - assert(callback.calledThrice, 'callback called thrice'); - assert.equal(callback.thirdCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.thirdCall.args[0], 'callback did not receive error'); - assert.strictEqual(callback.thirdCall.args[1], sample.mocks.transferJob, 'callback received transfer job'); - assert(console.log.calledWith('Updated transfer job: %s', sample.mocks.transferJob.name)); + assert.equal(sample.mocks.storagetransfer.transferJobs.patch.calledThrice, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.patch.thirdCall.args.slice(0, -1), [{ + auth: {}, + jobName: jobName, + resource: { + projectId: process.env.GCLOUD_PROJECT, + transferJob: { + name: jobName, + transferSpec: JSON.parse(options.value) + }, + updateTransferJobFieldMask: options.field + } + }]); + assert.equal(callback.calledThrice, true); + assert.deepEqual(callback.thirdCall.args, [null, sample.mocks.transferJob]); + assert.equal(console.log.calledThrice, true); + assert.deepEqual(console.log.thirdCall.args, ['Updated transfer job: %s', jobName]); }); it('should handle auth error', function () { @@ -215,14 +250,12 @@ describe('storage:transfer', function () { field: 'status', value: 'DISABLED' }; - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.updateTransferJob(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle patch error', function () { @@ -234,14 +267,12 @@ describe('storage:transfer', function () { field: 'status', value: 'DISABLED' }; - sample.mocks.storagetransfer.transferJobs.patch.callsArgWith(1, error); + sample.mocks.storagetransfer.transferJobs.patch.yields(error); sample.program.updateTransferJob(options, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -252,47 +283,51 @@ describe('storage:transfer', function () { sample.program.listTransferJobs(callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.firstCall.args[1], [sample.mocks.transferJob], 'callback received transfer jobs'); - - sample.mocks.storagetransfer.transferJobs.list.callsArgWith(1, null, {}); + assert.equal(sample.mocks.storagetransfer.transferJobs.list.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.list.firstCall.args.slice(0, -1), [{ + auth: {}, + filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT }) + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, [sample.mocks.transferJob]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d jobs!', 1]); + + sample.mocks.storagetransfer.transferJobs.list.yields(null, {}); sample.program.listTransferJobs(callback); - assert(callback.calledTwice, 'callback called twice'); - assert.equal(callback.secondCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.secondCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.secondCall.args[1], [], 'callback received no transfer jobs'); - assert(console.log.calledWith('Found %d jobs!', 1)); + assert.equal(sample.mocks.storagetransfer.transferJobs.list.calledTwice, true); + assert.deepEqual(sample.mocks.storagetransfer.transferJobs.list.secondCall.args.slice(0, -1), [{ + auth: {}, + filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT }) + }]); + assert.equal(callback.calledTwice, true); + assert.deepEqual(callback.secondCall.args, [null, []]); + assert.equal(console.log.calledOnce, true); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.listTransferJobs(callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle list error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferJobs.list.callsArgWith(1, error); + sample.mocks.storagetransfer.transferJobs.list.yields(error); sample.program.listTransferJobs(callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); }); @@ -303,55 +338,71 @@ describe('storage:transfer', function () { var sample = getSample(); var callback = sinon.stub(); + // Test that all operations get listed sample.program.listTransferOperations(undefined, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.firstCall.args[1], [sample.mocks.transferOperation], 'callback received transfer operations'); - + assert.equal(sample.mocks.storagetransfer.transferOperations.list.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.list.firstCall.args.slice(0, -1), [{ + name: 'transferOperations', + auth: {}, + filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT }) + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, [sample.mocks.transferOperation]]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found %d operations!', 1]); + + // Test that operations for a specific job get listed sample.program.listTransferOperations(jobName, callback); - assert(callback.calledTwice, 'callback called twice'); - assert.equal(callback.secondCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.secondCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.secondCall.args[1], [sample.mocks.transferOperation], 'callback received transfer operations'); - - sample.mocks.storagetransfer.transferOperations.list.callsArgWith(1, null, {}); + assert.equal(sample.mocks.storagetransfer.transferOperations.list.calledTwice, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.list.secondCall.args.slice(0, -1), [{ + name: 'transferOperations', + auth: {}, + filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT, job_names: [jobName] }) + }]); + assert.equal(callback.calledTwice, true); + assert.deepEqual(callback.secondCall.args, [null, [sample.mocks.transferOperation]]); + assert.equal(console.log.calledTwice, true); + assert.deepEqual(console.log.secondCall.args, ['Found %d operations!', 1]); + + // Test that operations for a specific job get listed when the API response with just an object + sample.mocks.storagetransfer.transferOperations.list.yields(null, {}); sample.program.listTransferOperations(jobName, callback); - assert(callback.calledThrice, 'callback called thrice'); - assert.equal(callback.thirdCall.args.length, 2, 'callback received 2 arguments'); - assert.ifError(callback.thirdCall.args[0], 'callback did not receive error'); - assert.deepEqual(callback.thirdCall.args[1], [], 'callback received no transfer operations'); + assert.equal(sample.mocks.storagetransfer.transferOperations.list.calledThrice, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.list.thirdCall.args.slice(0, -1), [{ + name: 'transferOperations', + auth: {}, + filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT, job_names: [jobName] }) + }]); + assert.equal(callback.calledThrice, true); + assert.deepEqual(callback.thirdCall.args, [null, []]); + assert.equal(console.log.calledTwice, true); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.listTransferOperations(undefined, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle list error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferOperations.list.callsArgWith(1, error); + sample.mocks.storagetransfer.transferOperations.list.yields(error); sample.program.listTransferOperations(undefined, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -362,38 +413,44 @@ describe('storage:transfer', function () { sample.program.getTransferOperation(transferOperationName, callback); - assert(callback.calledOnce, 'callback called once'); + assert.equal(callback.calledOnce, true); assert.equal(callback.firstCall.args.length, 2, 'callback received 2 arguments'); assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); assert.strictEqual(callback.firstCall.args[1], sample.mocks.transferOperation, 'callback received transfer operation'); + + assert.equal(sample.mocks.storagetransfer.transferOperations.get.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.get.firstCall.args.slice(0, -1), [{ + name: transferOperationName, + auth: {} + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null, sample.mocks.transferOperation]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Found transfer operation: %s', sample.mocks.transferOperation]); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.getTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle get error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferOperations.get.callsArgWith(1, error); + sample.mocks.storagetransfer.transferOperations.get.yields(error); sample.program.getTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -404,37 +461,43 @@ describe('storage:transfer', function () { sample.program.pauseTransferOperation(transferOperationName, callback); - assert(callback.calledOnce, 'callback called once'); + assert.equal(callback.calledOnce, true); assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); + + assert.equal(sample.mocks.storagetransfer.transferOperations.pause.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.pause.firstCall.args.slice(0, -1), [{ + name: transferOperationName, + auth: {} + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Paused transfer operation: %s', transferOperationName]); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.pauseTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle pause error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferOperations.pause.callsArgWith(1, error); + sample.mocks.storagetransfer.transferOperations.pause.yields(error); sample.program.pauseTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); @@ -445,37 +508,43 @@ describe('storage:transfer', function () { sample.program.resumeTransferOperation(transferOperationName, callback); - assert(callback.calledOnce, 'callback called once'); + assert.equal(callback.calledOnce, true); assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); assert.ifError(callback.firstCall.args[0], 'callback did not receive error'); + + assert.equal(sample.mocks.storagetransfer.transferOperations.resume.calledOnce, true); + assert.deepEqual(sample.mocks.storagetransfer.transferOperations.resume.firstCall.args.slice(0, -1), [{ + name: transferOperationName, + auth: {} + }]); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [null]); + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, ['Resumed transfer operation: %s', transferOperationName]); }); it('should handle auth error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.callsArgWith(0, error); + sample.mocks.googleapis.auth.getApplicationDefault.yields(error); sample.program.resumeTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); it('should handle resume error', function () { var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); - sample.mocks.storagetransfer.transferOperations.resume.callsArgWith(1, error); + sample.mocks.storagetransfer.transferOperations.resume.yields(error); sample.program.resumeTransferOperation(jobName, callback); - assert(callback.calledOnce, 'callback called once'); - assert.equal(callback.firstCall.args.length, 1, 'callback received 1 argument'); - assert(callback.firstCall.args[0], 'callback received error'); - assert.equal(callback.firstCall.args[0].message, error.message, 'error has correct message'); + assert.equal(callback.calledOnce, true); + assert.deepEqual(callback.firstCall.args, [error]); }); }); });