Skip to content

Commit 895529e

Browse files
Improve coverage in common. (#2156)
1 parent f569e1d commit 895529e

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

packages/common/src/util.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ util.PartialFailureError = createErrorClass('PartialFailureError', function(b) {
123123
* @param {function} callback - The callback function.
124124
*/
125125
function handleResp(err, resp, body, callback) {
126-
callback = callback || noop;
126+
callback = callback || util.noop;
127127

128128
var parsedResp = extend(
129129
true,
@@ -217,8 +217,7 @@ util.parseHttpRespBody = parseHttpRespBody;
217217
* stream has completed.
218218
*/
219219
function makeWritableStream(dup, options, onComplete) {
220-
onComplete = onComplete || noop;
221-
options = options || {};
220+
onComplete = onComplete || util.noop;
222221

223222
var writeStream = through();
224223
dup.setWritable(writeStream);

packages/common/test/service-object.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ describe('ServiceObject', function() {
363363
serviceObject.get(assert.ifError);
364364
});
365365

366+
it('handles not getting a config', function(done) {
367+
serviceObject.getMetadata = function() {
368+
done();
369+
};
370+
serviceObject.get(undefined, assert.ifError);
371+
});
372+
366373
it('should execute callback with error & metadata', function(done) {
367374
var error = new Error('Error.');
368375
var metadata = {};

packages/common/test/util.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ describe('common/util', function() {
338338
});
339339
});
340340

341+
it('uses a no-op callback if none is sent', function() {
342+
util.handleResp(undefined, {}, '');
343+
});
344+
341345
it('should parse response', function(done) {
342346
var err = { a: 'b', c: 'd' };
343347
var resp = { a: 'b', c: 'd' };
@@ -1759,6 +1763,18 @@ describe('common/util', function() {
17591763
done();
17601764
});
17611765
});
1766+
1767+
it('should not mistake non-function args for callbacks', function(done) {
1768+
var func = util.promisify(function(foo, optional) {
1769+
assert.strictEqual(arguments.length, 2);
1770+
assert(is.fn(optional));
1771+
optional(null);
1772+
});
1773+
1774+
func('foo').then(function() {
1775+
done();
1776+
});
1777+
});
17621778
});
17631779
});
17641780
});

0 commit comments

Comments
 (0)