From dbaf7b51921535ed2f6d75567d710f624a67e0b6 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Mon, 29 Aug 2016 13:55:03 -0700 Subject: [PATCH] Use a real Error in tests. (#192) --- bigquery/test/queries.test.js | 6 +++--- bigquery/test/tables.test.js | 2 +- logging/test/logs.test.js | 6 +++--- logging/test/sinks.test.js | 10 +++++----- pubsub/test/iam.test.js | 24 ++++++++++++------------ pubsub/test/subscriptions.test.js | 20 ++++++++++---------- pubsub/test/topics.test.js | 16 ++++++++-------- storage/test/acl.test.js | 6 +++--- storage/test/buckets.test.js | 6 +++--- storage/test/encryption.test.js | 4 ++-- storage/test/files.test.js | 18 +++++++++--------- translate/test/translate.test.js | 6 +++--- 12 files changed, 62 insertions(+), 62 deletions(-) diff --git a/bigquery/test/queries.test.js b/bigquery/test/queries.test.js index 6d9241365f..83051d1dd0 100644 --- a/bigquery/test/queries.test.js +++ b/bigquery/test/queries.test.js @@ -85,7 +85,7 @@ describe('bigquery:query', function () { }); it('should handle error', function () { - var error = Error('syncQueryError'); + var error = new Error('error'); var example = getSample(); example.mocks.bigquery.query = sinon.stub().callsArgWith(1, error); example.program.syncQuery(query, function (err, data) { @@ -121,7 +121,7 @@ describe('bigquery:query', function () { }); it('should handle error', function () { - var error = Error('asyncQueryError'); + var error = new Error('error'); var example = getSample(); example.mocks.bigquery.startQuery = sinon.stub().callsArgWith(1, error); example.program.asyncQuery(query, function (err, job) { @@ -193,7 +193,7 @@ describe('bigquery:query', function () { }); it('should handle error', function () { - var error = Error('asyncPollError'); + var error = new Error('error'); var example = getSample(); example.mocks.job.getQueryResults = sinon.stub().callsArgWith(0, error); example.program.asyncPoll(example.jobId, function (err, rows) { diff --git a/bigquery/test/tables.test.js b/bigquery/test/tables.test.js index 59cd0b3833..e2718f4954 100644 --- a/bigquery/test/tables.test.js +++ b/bigquery/test/tables.test.js @@ -278,7 +278,7 @@ describe('bigquery:tables', function () { }); it('should handle export error', function () { - var error = new Error('exportTableToGCSError'); + var error = new Error('error'); var example = getSample(); var callback = sinon.stub(); example.mocks.table.export.yields(error); diff --git a/logging/test/logs.test.js b/logging/test/logs.test.js index 535aed1731..40f5c8e3e3 100644 --- a/logging/test/logs.test.js +++ b/logging/test/logs.test.js @@ -74,7 +74,7 @@ describe('logging:entries', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.logging.getEntries = sinon.stub().callsArgWith(1, error); @@ -107,7 +107,7 @@ describe('logging:entries', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.log.write = sinon.stub().callsArgWith(1, error); @@ -137,7 +137,7 @@ describe('logging:entries', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.log.delete = sinon.stub().callsArgWith(0, error); diff --git a/logging/test/sinks.test.js b/logging/test/sinks.test.js index 5c404f065b..209939bec9 100644 --- a/logging/test/sinks.test.js +++ b/logging/test/sinks.test.js @@ -149,7 +149,7 @@ describe('logging:sinks', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.sink.create = sinon.stub().callsArgWith(1, error); @@ -180,7 +180,7 @@ describe('logging:sinks', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.sink.getMetadata = sinon.stub().callsArgWith(0, error); @@ -211,7 +211,7 @@ describe('logging:sinks', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.logging.getSinks = sinon.stub().callsArgWith(0, error); @@ -248,7 +248,7 @@ describe('logging:sinks', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.sink.setMetadata = sinon.stub().callsArgWith(1, error); @@ -278,7 +278,7 @@ describe('logging:sinks', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.sink.delete = sinon.stub().callsArgWith(0, error); diff --git a/pubsub/test/iam.test.js b/pubsub/test/iam.test.js index cdf17e73f2..c8a6308dac 100644 --- a/pubsub/test/iam.test.js +++ b/pubsub/test/iam.test.js @@ -72,8 +72,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.iam.getPolicy.callsArgWith(0, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.iam.getPolicy.callsArgWith(0, error); sample.program.getTopicPolicy(topicName, function (err) { assert(err); assert(err.message === 'error'); @@ -100,8 +100,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.iam.getPolicy.callsArgWith(0, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.iam.getPolicy.callsArgWith(0, error); sample.program.getSubscriptionPolicy(subscriptionName, function (err) { assert(err); assert(err.message === 'error'); @@ -128,8 +128,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.iam.setPolicy.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.iam.setPolicy.callsArgWith(1, error); sample.program.setTopicPolicy(topicName, function (err) { assert(err); assert(err.message === 'error'); @@ -156,8 +156,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.iam.setPolicy.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.iam.setPolicy.callsArgWith(1, error); sample.program.setSubscriptionPolicy(subscriptionName, function (err) { assert(err); assert(err.message === 'error'); @@ -184,8 +184,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.iam.testPermissions.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.iam.testPermissions.callsArgWith(1, error); sample.program.testTopicPermissions(topicName, function (err, permissions) { assert(err); assert(err.message === 'error'); @@ -213,8 +213,8 @@ describe('pubsub:iam', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.iam.testPermissions.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.iam.testPermissions.callsArgWith(1, error); sample.program.testSubscriptionPermissions(subscriptionName, function (err, permissions) { assert(err); assert(err.message === 'error'); diff --git a/pubsub/test/subscriptions.test.js b/pubsub/test/subscriptions.test.js index 103030c84e..5860616562 100644 --- a/pubsub/test/subscriptions.test.js +++ b/pubsub/test/subscriptions.test.js @@ -91,8 +91,8 @@ describe('pubsub:subscriptions', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.pubsub.subscribe.callsArgWith(3, new Error(error)); + var error = new Error('error'); + sample.mocks.pubsub.subscribe.callsArgWith(3, error); sample.program.createSubscription(topicName, subscriptionName, function (err) { assert(err); assert(err.message === 'error'); @@ -118,8 +118,8 @@ describe('pubsub:subscriptions', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.delete.callsArgWith(0, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.delete.callsArgWith(0, error); sample.program.deleteSubscription(subscriptionName, function (err) { assert(err); assert(err.message === 'error'); @@ -146,8 +146,8 @@ describe('pubsub:subscriptions', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.pubsub.getSubscriptions.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.pubsub.getSubscriptions.callsArgWith(1, error); sample.program.listSubscriptions(undefined, function (err, subscriptions) { assert(err); assert(err.message === 'error'); @@ -176,8 +176,8 @@ describe('pubsub:subscriptions', function () { }); it('should handle pull error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.pull.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.pull.callsArgWith(1, error); sample.program.pullMessages(subscriptionName, function (err, messages) { assert(err); assert(err.message === 'error'); @@ -186,8 +186,8 @@ describe('pubsub:subscriptions', function () { }); it('should handle ack error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.subscription.ack.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.subscription.ack.callsArgWith(1, error); sample.program.pullMessages(subscriptionName, function (err) { assert(err); assert(err.message === 'error'); diff --git a/pubsub/test/topics.test.js b/pubsub/test/topics.test.js index 0224bb7580..06461013a3 100644 --- a/pubsub/test/topics.test.js +++ b/pubsub/test/topics.test.js @@ -67,8 +67,8 @@ describe('pubsub:topics', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.get.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.get.callsArgWith(1, error); sample.program.createTopic(topicName, function (err) { assert(err); assert(err.message === 'error'); @@ -94,8 +94,8 @@ describe('pubsub:topics', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.delete.callsArgWith(0, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.delete.callsArgWith(0, error); sample.program.deleteTopic(topicName, function (err) { assert(err); assert(err.message === 'error'); @@ -138,8 +138,8 @@ describe('pubsub:topics', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.topic.publish.callsArgWith(1, new Error(error)); + var error = new Error('error'); + sample.mocks.topic.publish.callsArgWith(1, error); sample.program.publishMessage(topicName, '{"data":"hello world"}', function (err, messageIds) { assert(err); assert(err.message === 'error'); @@ -159,8 +159,8 @@ describe('pubsub:topics', function () { }); it('should handle error', function () { var sample = getSample(); - var error = 'error'; - sample.mocks.pubsub.getTopics.callsArgWith(0, new Error(error)); + var error = new Error('error'); + sample.mocks.pubsub.getTopics.callsArgWith(0, error); sample.program.listTopics(function (err, topics) { assert(err); assert(err.message === 'error'); diff --git a/storage/test/acl.test.js b/storage/test/acl.test.js index 5931c583a9..9898da765b 100644 --- a/storage/test/acl.test.js +++ b/storage/test/acl.test.js @@ -140,7 +140,7 @@ describe('storage:acl', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.bucket.acl.add = sinon.stub().callsArgWith(1, error); @@ -263,7 +263,7 @@ describe('storage:acl', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -346,7 +346,7 @@ describe('storage:acl', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { diff --git a/storage/test/buckets.test.js b/storage/test/buckets.test.js index 787f1eb9be..11aae5c5e9 100644 --- a/storage/test/buckets.test.js +++ b/storage/test/buckets.test.js @@ -65,7 +65,7 @@ describe('storage:buckets', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.bucket.create = sinon.stub().callsArgWith(0, error); @@ -96,7 +96,7 @@ describe('storage:buckets', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.storage.getBuckets = sinon.stub().callsArgWith(0, error); @@ -128,7 +128,7 @@ describe('storage:buckets', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.bucket.delete = sinon.stub().callsArgWith(0, error); diff --git a/storage/test/encryption.test.js b/storage/test/encryption.test.js index 5f0d88e8d7..e4c87940fd 100644 --- a/storage/test/encryption.test.js +++ b/storage/test/encryption.test.js @@ -90,7 +90,7 @@ describe('storage:encryption', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -135,7 +135,7 @@ describe('storage:encryption', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { diff --git a/storage/test/files.test.js b/storage/test/files.test.js index 4a22092148..81564b54cf 100644 --- a/storage/test/files.test.js +++ b/storage/test/files.test.js @@ -77,7 +77,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.bucket.getFiles = sinon.stub().callsArgWith(0, error); @@ -144,7 +144,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var prefix = '/a'; @@ -185,7 +185,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -227,7 +227,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -266,7 +266,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -305,7 +305,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -343,7 +343,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -384,7 +384,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { @@ -426,7 +426,7 @@ describe('storage:files', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = { diff --git a/translate/test/translate.test.js b/translate/test/translate.test.js index acc2f4d102..bff3027bf1 100644 --- a/translate/test/translate.test.js +++ b/translate/test/translate.test.js @@ -69,7 +69,7 @@ describe('translate:translate', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.translate.detect = sinon.stub().callsArgWith(1, error); @@ -100,7 +100,7 @@ describe('translate:translate', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); sample.mocks.translate.getLanguages = sinon.stub().callsArgWith(0, error); @@ -141,7 +141,7 @@ describe('translate:translate', function () { }); it('should handle error', function () { - var error = 'error'; + var error = new Error('error'); var sample = getSample(); var callback = sinon.stub(); var options = {