Skip to content

Commit 56729ff

Browse files
prevent GRPC from running in the docs test env
1 parent ab4261a commit 56729ff

File tree

10 files changed

+84
-37
lines changed

10 files changed

+84
-37
lines changed

lib/common/grpc-service.js

+8
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ nodeutil.inherits(GrpcService, Service);
168168
* @param {function=} callback - The callback function.
169169
*/
170170
GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
171+
if (global.GCLOUD_TEST_ENVIRONMENT) {
172+
return global.GCLOUD_TEST_ENVIRONMENT;
173+
}
174+
171175
var self = this;
172176
var proto = this.proto;
173177

@@ -184,6 +188,10 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
184188
grpcOpts.deadline = new Date(Date.now() + protoOpts.timeout);
185189
}
186190

191+
// Clean up gcloud-specific options.
192+
delete reqOpts.autoPaginate;
193+
delete reqOpts.autoPaginateVal;
194+
187195
var service = new proto[protoOpts.service](
188196
this.baseUrl,
189197
this.grpcCredentials

lib/pubsub/iam.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var GrpcService = require('../common/grpc-service.js');
7777
*/
7878
function IAM(pubsub, id) {
7979
var config = {
80-
baseUrl: pubsub.baseUrl,
80+
baseUrl: pubsub.defaultBaseUrl_,
8181
service: 'iam',
8282
apiVersion: 'v1',
8383
scopes: [

lib/pubsub/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ function PubSub(options) {
8888
return new PubSub(options);
8989
}
9090

91+
this.defaultBaseUrl_ = 'pubsub.googleapis.com';
9192
this.determineBaseUrl_();
9293

9394
var config = {
94-
baseUrl: this.baseUrl,
95-
customEndpoint: this.customEndpoint,
95+
baseUrl: this.baseUrl_,
96+
customEndpoint: this.customEndpoint_,
9697
service: 'pubsub',
9798
apiVersion: 'v1',
9899
scopes: [
@@ -584,18 +585,16 @@ PubSub.prototype.topic = function(name) {
584585
* @private
585586
*/
586587
PubSub.prototype.determineBaseUrl_ = function() {
587-
var baseUrl;
588+
var baseUrl = this.defaultBaseUrl_;
588589
var leadingProtocol = new RegExp('^https*://');
589590
var trailingSlashes = new RegExp('/*$');
590591

591592
if (process.env.PUBSUB_EMULATOR_HOST) {
592-
this.customEndpoint = true;
593+
this.customEndpoint_ = true;
593594
baseUrl = process.env.PUBSUB_EMULATOR_HOST;
594-
} else {
595-
baseUrl = 'pubsub.googleapis.com';
596595
}
597596

598-
this.baseUrl = baseUrl
597+
this.baseUrl_ = baseUrl
599598
.replace(leadingProtocol, '')
600599
.replace(trailingSlashes, '');
601600
};

lib/pubsub/subscription.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ Subscription.prototype.pull = function(options, callback) {
589589
* @resource [Subscriptions: modifyAckDeadline API Documentation]{@link https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/modifyAckDeadline}
590590
*
591591
* @param {object} options - The configuration object.
592-
* @param {number|number[]} options.ackIds - The ack id(s) to change.
592+
* @param {string|string[]} options.ackIds - The ack id(s) to change.
593593
* @param {number} options.seconds - Number of seconds after call is made to
594594
* set the deadline of the ack.
595595
* @param {Function=} callback - The callback function.
596596
*
597597
* @example
598598
* var options = {
599-
* ackIds: [123],
599+
* ackIds: ['abc'],
600600
* seconds: 10 // Expire in 10 seconds from call.
601601
* };
602602
*

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"gcs-resumable-upload": "^0.4.0",
9797
"google-auto-auth": "^0.2.0",
9898
"google-proto-files": "^0.1.1",
99-
"grpc": "grpc/grpc#00c3947782bf0b59d913d567a95fc8e7e49702f3",
99+
"grpc": "^0.13.0-pre1",
100100
"hash-stream-validation": "^0.1.0",
101101
"is": "^3.0.1",
102102
"methmeth": "^1.0.0",
@@ -127,7 +127,6 @@
127127
"jshint": "^2.9.1",
128128
"mitm": "^1.1.0",
129129
"mocha": "^2.1.0",
130-
"mockery": "^1.4.0",
131130
"mockery-next": "^2.0.1-3",
132131
"node-uuid": "^1.4.3",
133132
"tmp": "0.0.27"

test/common/grpc-service.js

+24
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ describe('GrpcService', function() {
187187
grpcService.proto.service = ProtoService;
188188
});
189189

190+
it('should not run in the gcloud testing environment', function() {
191+
global.GCLOUD_TEST_ENVIRONMENT = true;
192+
assert.strictEqual(grpcService.request(), global.GCLOUD_TEST_ENVIRONMENT);
193+
delete global.GCLOUD_TEST_ENVIRONMENT;
194+
});
195+
190196
it('should get an auth client', function(done) {
191197
delete grpcService.grpcCredentials;
192198

@@ -261,6 +267,24 @@ describe('GrpcService', function() {
261267
grpcService.request(PROTO_OPTS, REQ_OPTS, assert.ifError);
262268
});
263269

270+
it('should remove gcloud-specific options', function(done) {
271+
grpcService.proto = {};
272+
grpcService.proto.service = function() {
273+
return {
274+
method: function(reqOpts) {
275+
assert.strictEqual(reqOpts.autoPaginate, undefined);
276+
assert.strictEqual(reqOpts.autoPaginateVal, undefined);
277+
done();
278+
}
279+
};
280+
};
281+
282+
grpcService.request(PROTO_OPTS, {
283+
autoPaginate: true,
284+
autoPaginateVal: true
285+
}, assert.ifError);
286+
});
287+
264288
describe('error', function() {
265289
var HTTP_ERROR_CODE_MAP = {
266290
0: {

test/docs.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,19 @@ describe('documentation', function() {
8181
return console;
8282
}, {});
8383

84+
// Set a global to indicate to any interested function inside of gcloud
85+
// that this is a testing environment.
86+
global.GCLOUD_TEST_ENVIRONMENT = true;
87+
8488
var sandbox = {
8589
gcloud: gcloud,
8690
require: require,
8791
process: process,
8892
console: mockConsole,
8993
Buffer: Buffer,
9094
Date: Date,
91-
Array: Array
95+
Array: Array,
96+
global: global
9297
};
9398

9499
fileDocBlocks.methods.forEach(function(method) {

test/pubsub/iam.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('IAM', function() {
3535
var iam;
3636

3737
var PUBSUB = {
38-
baseUrl: 'base-url',
38+
defaultBaseUrl_: 'base-url',
3939
options: {}
4040
};
4141
var ID = 'id';
@@ -67,7 +67,7 @@ describe('IAM', function() {
6767
var config = iam.calledWith_[0];
6868
var options = iam.calledWith_[1];
6969

70-
assert.strictEqual(config.baseUrl, PUBSUB.baseUrl);
70+
assert.strictEqual(config.baseUrl, PUBSUB.defaultBaseUrl_);
7171
assert.strictEqual(config.service, 'iam');
7272
assert.strictEqual(config.apiVersion, 'v1');
7373
assert.deepEqual(config.scopes, [

test/pubsub/index.js

+25-13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ describe('PubSub', function() {
6363
var pubsub;
6464
var OPTIONS = { projectId: PROJECT_ID };
6565

66+
var PUBSUB_EMULATOR_HOST = process.env.PUBSUB_EMULATOR_HOST;
67+
6668
before(function() {
6769
mockery.registerMock('../../lib/common/grpc-service.js', FakeGrpcService);
6870
mockery.registerMock('../../lib/common/stream-router.js', fakeStreamRouter);
@@ -75,10 +77,15 @@ describe('PubSub', function() {
7577
warnOnUnregistered: false
7678
});
7779

80+
delete process.env.PUBSUB_EMULATOR_HOST;
7881
PubSub = require('../../lib/pubsub');
7982
});
8083

8184
after(function() {
85+
if (PUBSUB_EMULATOR_HOST) {
86+
process.env.PUBSUB_EMULATOR_HOST = PUBSUB_EMULATOR_HOST;
87+
}
88+
8289
mockery.deregisterAll();
8390
mockery.disable();
8491
});
@@ -127,6 +134,10 @@ describe('PubSub', function() {
127134
]);
128135
});
129136

137+
it('should set the defaultBaseUrl_', function() {
138+
assert.strictEqual(pubsub.defaultBaseUrl_, 'pubsub.googleapis.com');
139+
});
140+
130141
it('should use the PUBSUB_EMULATOR_HOST env var', function() {
131142
var pubSubHost = 'pubsub-host';
132143
process.env.PUBSUB_EMULATOR_HOST = pubSubHost;
@@ -719,39 +730,40 @@ describe('PubSub', function() {
719730
delete process.env.PUBSUB_EMULATOR_HOST;
720731
});
721732

722-
it('should default to pubsub.googleapis.com', function() {
723-
pubsub.determineBaseUrl_();
733+
it('should default to defaultBaseUrl_', function() {
734+
var defaultBaseUrl_ = 'defaulturl';
735+
pubsub.defaultBaseUrl_ = defaultBaseUrl_;
724736

725-
var expectedBaseUrl = 'pubsub.googleapis.com';
726-
assert.strictEqual(pubsub.baseUrl, expectedBaseUrl);
737+
pubsub.determineBaseUrl_();
738+
assert.strictEqual(pubsub.baseUrl_, defaultBaseUrl_);
727739
});
728740

729741
it('should remove slashes from the baseUrl', function() {
730742
var expectedBaseUrl = 'localhost:8080';
731743

732744
setHost('localhost:8080/');
733745
pubsub.determineBaseUrl_();
734-
assert.strictEqual(pubsub.baseUrl, expectedBaseUrl);
746+
assert.strictEqual(pubsub.baseUrl_, expectedBaseUrl);
735747

736748
setHost('localhost:8080//');
737749
pubsub.determineBaseUrl_();
738-
assert.strictEqual(pubsub.baseUrl, expectedBaseUrl);
750+
assert.strictEqual(pubsub.baseUrl_, expectedBaseUrl);
739751
});
740752

741753
it('should remove the protocol if specified', function() {
742754
setHost('http://localhost:8080');
743755
pubsub.determineBaseUrl_();
744-
assert.strictEqual(pubsub.baseUrl, 'localhost:8080');
756+
assert.strictEqual(pubsub.baseUrl_, 'localhost:8080');
745757

746758
setHost('https://localhost:8080');
747759
pubsub.determineBaseUrl_();
748-
assert.strictEqual(pubsub.baseUrl, 'localhost:8080');
760+
assert.strictEqual(pubsub.baseUrl_, 'localhost:8080');
749761
});
750762

751-
it('should not set customEndpoint when using default endpoint', function() {
763+
it('should not set customEndpoint_ when using default baseurl', function() {
752764
var pubsub = new PubSub({ projectId: PROJECT_ID });
753765
pubsub.determineBaseUrl_();
754-
assert.strictEqual(pubsub.customEndpoint, undefined);
766+
assert.strictEqual(pubsub.customEndpoint_, undefined);
755767
});
756768

757769
describe('with PUBSUB_EMULATOR_HOST environment variable', function() {
@@ -767,12 +779,12 @@ describe('PubSub', function() {
767779

768780
it('should use the PUBSUB_EMULATOR_HOST env var', function() {
769781
pubsub.determineBaseUrl_();
770-
assert.strictEqual(pubsub.baseUrl, PUBSUB_EMULATOR_HOST);
782+
assert.strictEqual(pubsub.baseUrl_, PUBSUB_EMULATOR_HOST);
771783
});
772784

773-
it('should set customEndpoint', function() {
785+
it('should set customEndpoint_', function() {
774786
pubsub.determineBaseUrl_();
775-
assert.strictEqual(pubsub.customEndpoint, true);
787+
assert.strictEqual(pubsub.customEndpoint_, true);
776788
});
777789
});
778790
});

test/pubsub/subscription.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ describe('Subscription', function() {
5252
var messageBinary = new Buffer(message).toString('binary');
5353
var messageObj = {
5454
receivedMessages: [{
55-
ackId: 3,
55+
ackId: 'abc',
5656
message: {
5757
data: messageBuffer,
5858
messageId: 7
5959
}
6060
}]
6161
};
6262
var expectedMessage = {
63-
ackId: 3,
63+
ackId: 'abc',
6464
data: message,
6565
id: 7
6666
};
6767
var expectedMessageAsBinary = {
68-
ackId: 3,
68+
ackId: 'abc',
6969
data: messageBinary,
7070
id: 7
7171
};
@@ -226,7 +226,7 @@ describe('Subscription', function() {
226226
var attributes = {};
227227

228228
var msg = Subscription.formatMessage_({
229-
ackId: 3,
229+
ackId: 'abc',
230230
message: {
231231
data: stringified,
232232
messageId: 7,
@@ -235,7 +235,7 @@ describe('Subscription', function() {
235235
});
236236

237237
assert.deepEqual(msg, {
238-
ackId: 3,
238+
ackId: 'abc',
239239
id: 7,
240240
data: obj,
241241
attributes: attributes
@@ -291,7 +291,7 @@ describe('Subscription', function() {
291291
});
292292

293293
it('should make an array out of ids', function(done) {
294-
var ID = 1;
294+
var ID = 'abc';
295295

296296
subscription.request = function(protoOpts, reqOpts) {
297297
assert.deepEqual(reqOpts.ackIds, [ID]);
@@ -679,7 +679,7 @@ describe('Subscription', function() {
679679
receivedMessages: [{
680680
ackId: 1,
681681
message: {
682-
messageId: '123',
682+
messageId: 'abc',
683683
data: new Buffer('message').toString('base64')
684684
}
685685
}]
@@ -709,14 +709,14 @@ describe('Subscription', function() {
709709

710710
assert.deepEqual(reqOpts, {
711711
subscription: subscription.name,
712-
ackIds: [123],
712+
ackIds: ['abc'],
713713
ackDeadlineSeconds: 10
714714
});
715715

716716
done();
717717
};
718718

719-
subscription.setAckDeadline({ ackIds: [123], seconds: 10 }, done);
719+
subscription.setAckDeadline({ ackIds: ['abc'], seconds: 10 }, done);
720720
});
721721

722722
it('should execute the callback', function(done) {

0 commit comments

Comments
 (0)