Skip to content

Commit a8cb374

Browse files
tests: fix assert.throws() usage (googleapis#1468)
1 parent 3dc18e1 commit a8cb374

File tree

14 files changed

+43
-53
lines changed

14 files changed

+43
-53
lines changed

packages/compute/test/zone.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('Zone', function() {
182182
it('should throw if a target is not provided', function() {
183183
assert.throws(function() {
184184
zone.createAutoscaler(NAME, {}, assert.ifError);
185-
}, 'Cannot create an autoscaler without a target.');
185+
}, /Cannot create an autoscaler without a target\./);
186186
});
187187

188188
it('should make the correct request', function(done) {

packages/datastore/test/request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ describe('Request', function() {
13051305

13061306
assert.throws(function() {
13071307
request.request_({ method: 'runQuery' }, reqOpts, assert.ifError);
1308-
}, 'Read consistency cannot be specified in a transaction.');
1308+
}, /Read consistency cannot be specified in a transaction\./);
13091309
});
13101310
});
13111311
});

packages/logging/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ describe('Logging', function() {
170170
it('should throw if a name is not provided', function() {
171171
assert.throws(function() {
172172
logging.createSink();
173-
}, 'A sink name must be provided.');
173+
}, /A sink name must be provided\./);
174174
});
175175

176176
it('should throw if a config object is not provided', function() {
177177
assert.throws(function() {
178178
logging.createSink(SINK_NAME);
179-
}, 'A sink configuration object must be provided.');
179+
}, /A sink configuration object must be provided\./);
180180
});
181181

182182
it('should set acls for a Bucket destination', function(done) {

packages/prediction/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Prediction', function() {
128128
it('should throw if a model ID is not provided', function() {
129129
assert.throws(function() {
130130
prediction.createModel();
131-
}, /A model ID is required/);
131+
}, /A model ID is required\./);
132132
});
133133

134134
it('should make the correct API request', function(done) {
@@ -379,7 +379,7 @@ describe('Prediction', function() {
379379
it('should throw if a name is not provided', function() {
380380
assert.throws(function() {
381381
prediction.model();
382-
}, /A model ID is required/);
382+
}, /A model ID is required\./);
383383
});
384384

385385
it('should return a Model', function() {

packages/pubsub/test/iam.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('IAM', function() {
9393
it('should throw an error if a policy is not supplied', function() {
9494
assert.throws(function() {
9595
iam.setPolicy(util.noop);
96-
}, /A policy object is required/);
96+
}, /A policy object is required\./);
9797
});
9898

9999
it('should make the correct API request', function(done) {
@@ -117,7 +117,7 @@ describe('IAM', function() {
117117
it('should throw an error if permissions are missing', function() {
118118
assert.throws(function() {
119119
iam.testPermissions(util.noop);
120-
}, /Permissions are required/);
120+
}, /Permissions are required\./);
121121
});
122122

123123
it('should make the correct API request', function(done) {

packages/pubsub/test/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ describe('PubSub', function() {
468468
it('should throw if no Topic is provided', function() {
469469
assert.throws(function() {
470470
pubsub.subscribe();
471-
}, /A Topic is required.*/);
471+
}, /A Topic is required for a new subscription\./);
472472
});
473473

474474
it('should throw if no sub name is provided', function() {
475475
assert.throws(function() {
476476
pubsub.subscribe('topic');
477-
}, /A subscription name is required.*/);
477+
}, /A subscription name is required for a new subscription\./);
478478
});
479479

480480
it('should not require configuration options', function(done) {
@@ -680,7 +680,7 @@ describe('PubSub', function() {
680680
it('should throw if no name is provided', function() {
681681
assert.throws(function() {
682682
pubsub.subscription();
683-
}, /The name of a subscription is required/);
683+
}, /The name of a subscription is required\./);
684684
});
685685

686686
it('should return a Subscription object', function() {
@@ -716,7 +716,7 @@ describe('PubSub', function() {
716716
it('should throw if a name is not provided', function() {
717717
assert.throws(function() {
718718
pubsub.topic();
719-
}, /name must be specified/);
719+
}, /A name must be specified for a new topic\./);
720720
});
721721

722722
it('should return a Topic object', function() {

packages/pubsub/test/subscription.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ describe('Subscription', function() {
258258
it('should throw if no IDs are provided', function() {
259259
assert.throws(function() {
260260
subscription.ack();
261-
}, /At least one ID/);
261+
}, /At least one ID must be specified before it can be acknowledged\./);
262262
assert.throws(function() {
263263
subscription.ack([]);
264-
}, /At least one ID/);
264+
}, /At least one ID must be specified before it can be acknowledged\./);
265265
});
266266

267267
it('should accept a single id', function() {

packages/pubsub/test/topic.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ describe('Topic', function() {
185185
it('should throw if no message is provided', function() {
186186
assert.throws(function() {
187187
topic.publish();
188-
}, /Cannot publish without a message/);
188+
}, /Cannot publish without a message\./);
189189

190190
assert.throws(function() {
191191
topic.publish([]);
192-
}, /Cannot publish without a message/);
192+
}, /Cannot publish without a message\./);
193193
});
194194

195195
it('should throw if a message has no data', function() {
196196
assert.throws(function() {
197197
topic.publish({});
198-
}, /Cannot publish message without a `data` property/);
198+
}, /Cannot publish message without a `data` property\./);
199199
});
200200

201201
it('should send correct api request', function(done) {

packages/resource/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ describe('Resource', function() {
327327

328328
assert.throws(function() {
329329
resourceWithoutProjectId.project();
330-
}, /A project ID is required/);
330+
}, /A project ID is required\./);
331331
});
332332
});
333333
});

packages/storage/test/bucket.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,19 @@ describe('Bucket', function() {
194194

195195
describe('combine', function() {
196196
it('should throw if invalid sources are not provided', function() {
197-
var error = 'You must provide at least two source files.';
198-
199197
assert.throws(function() {
200198
bucket.combine();
201-
}, new RegExp(error));
199+
}, /You must provide at least two source files\./);
202200

203201
assert.throws(function() {
204202
bucket.combine(['1']);
205-
}, new RegExp(error));
203+
}, /You must provide at least two source files\./);
206204
});
207205

208206
it('should throw if a destination is not provided', function() {
209-
var error = 'A destination file must be specified.';
210-
211207
assert.throws(function() {
212208
bucket.combine(['1', '2']);
213-
}, new RegExp(error));
209+
}, /A destination file must be specified\./);
214210
});
215211

216212
it('should accept string or file input for sources', function(done) {
@@ -292,7 +288,7 @@ describe('Bucket', function() {
292288
it('should throw if content type cannot be determined', function() {
293289
assert.throws(function() {
294290
bucket.combine(['1', '2'], 'destination');
295-
}, /A content type could not be detected/);
291+
}, /A content type could not be detected for the destination file\./);
296292
});
297293

298294
it('should make correct API request', function(done) {
@@ -395,13 +391,13 @@ describe('Bucket', function() {
395391
it('should throw if an ID is not provided', function() {
396392
assert.throws(function() {
397393
bucket.createChannel();
398-
}, 'An ID is required to create a channel.');
394+
}, /An ID is required to create a channel\./);
399395
});
400396

401397
it('should throw if an address is not provided', function() {
402398
assert.throws(function() {
403399
bucket.createChannel(ID, {});
404-
}, 'An address is required to create a channel.');
400+
}, /An address is required to create a channel\./);
405401
});
406402

407403
it('should make the correct request', function(done) {
@@ -607,7 +603,7 @@ describe('Bucket', function() {
607603
it('should throw if no name is provided', function() {
608604
assert.throws(function() {
609605
bucket.file();
610-
}, /A file name must be specified/);
606+
}, /A file name must be specified\./);
611607
});
612608

613609
it('should return a File object', function() {

packages/storage/test/file.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('File', function() {
235235
it('should throw if no destination is provided', function() {
236236
assert.throws(function() {
237237
file.copy();
238-
}, /should have a name/);
238+
}, /Destination file should have a name\./);
239239
});
240240

241241
it('should URI encode file names', function(done) {
@@ -335,7 +335,7 @@ describe('File', function() {
335335
it('should throw if a destination cannot be parsed', function() {
336336
assert.throws(function() {
337337
file.copy(function() {});
338-
}, /should have a name/);
338+
}, /Destination file should have a name\./);
339339
});
340340
});
341341

@@ -479,21 +479,21 @@ describe('File', function() {
479479
start: 3,
480480
end: 8
481481
});
482-
}, /Cannot use validation with file ranges/);
482+
}, /Cannot use validation with file ranges \(start\/end\)\./);
483483

484484
assert.throws(function() {
485485
file.createReadStream({
486486
validation: true,
487487
start: 3
488488
});
489-
}, /Cannot use validation with file ranges/);
489+
}, /Cannot use validation with file ranges \(start\/end\)\./);
490490

491491
assert.throws(function() {
492492
file.createReadStream({
493493
validation: true,
494494
end: 8
495495
});
496-
}, /Cannot use validation with file ranges/);
496+
}, /Cannot use validation with file ranges \(start\/end\)\./);
497497

498498
assert.doesNotThrow(function() {
499499
file.createReadStream({
@@ -1600,7 +1600,7 @@ describe('File', function() {
16001600
file.getSignedPolicy({
16011601
expires: expires
16021602
}, function() {});
1603-
}, /cannot be in the past/);
1603+
}, /An expiration date cannot be in the past\./);
16041604
});
16051605
});
16061606

@@ -1635,7 +1635,7 @@ describe('File', function() {
16351635
expires: Date.now() + 5,
16361636
equals: [{}]
16371637
}, function() {});
1638-
}, /Equals condition must be an array/);
1638+
}, /Equals condition must be an array of 2 elements\./);
16391639
});
16401640

16411641
it('should throw if equal condition length is not 2', function() {
@@ -1644,7 +1644,7 @@ describe('File', function() {
16441644
expires: Date.now() + 5,
16451645
equals: [['1', '2', '3']]
16461646
}, function() {});
1647-
}, /Equals condition must be an array of 2 elements/);
1647+
}, /Equals condition must be an array of 2 elements\./);
16481648
});
16491649
});
16501650

@@ -1679,7 +1679,7 @@ describe('File', function() {
16791679
expires: Date.now() + 5,
16801680
startsWith: [{}]
16811681
}, function() {});
1682-
}, /StartsWith condition must be an array/);
1682+
}, /StartsWith condition must be an array of 2 elements\./);
16831683
});
16841684

16851685
it('should throw if prefix condition length is not 2', function() {
@@ -1688,7 +1688,7 @@ describe('File', function() {
16881688
expires: Date.now() + 5,
16891689
startsWith: [['1', '2', '3']]
16901690
}, function() {});
1691-
}, /StartsWith condition must be an array of 2 elements/);
1691+
}, /StartsWith condition must be an array of 2 elements\./);
16921692
});
16931693
});
16941694

@@ -1711,7 +1711,7 @@ describe('File', function() {
17111711
expires: Date.now() + 5,
17121712
contentLengthRange: [{max: 1}]
17131713
}, function() {});
1714-
}, /ContentLengthRange must have numeric min & max fields/);
1714+
}, /ContentLengthRange must have numeric min & max fields\./);
17151715
});
17161716

17171717
it('should throw if content length has no max', function() {
@@ -1720,7 +1720,7 @@ describe('File', function() {
17201720
expires: Date.now() + 5,
17211721
contentLengthRange: [{min: 0}]
17221722
}, function() {});
1723-
}, /ContentLengthRange must have numeric min & max fields/);
1723+
}, /ContentLengthRange must have numeric min & max fields\./);
17241724
});
17251725
});
17261726
});
@@ -1962,7 +1962,7 @@ describe('File', function() {
19621962
action: 'read',
19631963
expires: expires
19641964
}, function() {});
1965-
}, /cannot be in the past/);
1965+
}, /An expiration date cannot be in the past\./);
19661966
});
19671967
});
19681968

@@ -2077,12 +2077,6 @@ describe('File', function() {
20772077
});
20782078

20792079
describe('move', function() {
2080-
it('should throw if no destination is provided', function() {
2081-
assert.throws(function() {
2082-
file.move();
2083-
}, /should have a name/);
2084-
});
2085-
20862080
describe('copy to destination', function() {
20872081
function assertCopyFile(file, expectedDestination, callback) {
20882082
file.copy = function(destination) {

packages/storage/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('Storage', function() {
118118
it('should throw if no name was provided', function() {
119119
assert.throws(function() {
120120
storage.bucket();
121-
}, /A bucket name is needed/);
121+
}, /A bucket name is needed to use Google Cloud Storage\./);
122122
});
123123

124124
it('should accept a string for a name', function() {
@@ -187,7 +187,7 @@ describe('Storage', function() {
187187
it('should throw if no name is provided', function() {
188188
assert.throws(function() {
189189
storage.createBucket();
190-
}, /A name is required/);
190+
}, /A name is required to create a bucket\./);
191191
});
192192

193193
it('should execute callback with bucket', function(done) {

packages/translate/test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('Translate', function() {
8181
it('should throw if an API key is not provided', function() {
8282
assert.throws(function() {
8383
new Translate({});
84-
}, 'An API key is required to use the Translate API.');
84+
}, /An API key is required to use the Translate API\./);
8585
});
8686

8787
it('should localize the options', function() {
@@ -266,7 +266,7 @@ describe('Translate', function() {
266266
it('should throw if `to` is not provided', function() {
267267
assert.throws(function() {
268268
translate.translate(INPUT, { from: SOURCE_LANG_CODE }, util.noop);
269-
}, 'A target language is required to perform a translation.');
269+
}, /A target language is required to perform a translation\./);
270270
});
271271

272272
it('should make the correct API request', function(done) {

packages/vision/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ describe('Vision', function() {
262262

263263
assert.throws(function() {
264264
vision.detect(IMAGE, type, assert.ifError);
265-
}, 'Requested detection feature not found: ' + type);
265+
}, /Requested detection feature not found: not-real-type/);
266266
});
267267

268268
it('should format the correct config', function(done) {

0 commit comments

Comments
 (0)