Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce x-goog-api-client for common-grpc #2164

Merged
merged 3 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/common-grpc/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var duplexify = require('duplexify');
var extend = require('extend');
var googleProtoFiles = require('google-proto-files');
var grpc = require('grpc');
var grpcVersion = require('grpc/package.json').version;
var is = require('is');
var nodeutil = require('util');
var path = require('path');
Expand Down Expand Up @@ -178,6 +179,11 @@ function GrpcService(config, options) {

this.grpcMetadata = new grpc.Metadata();

this.grpcMetadata.add('x-goog-api-client', [
'gl-node/' + process.versions.node,
'gccl/' + (config.packageJson.version || ''),

This comment was marked as spam.

This comment was marked as spam.

'grpc/' + grpcVersion

This comment was marked as spam.

This comment was marked as spam.

].join(' '));
if (config.grpcMetadata) {

This comment was marked as spam.

This comment was marked as spam.

for (var prop in config.grpcMetadata) {
if (config.grpcMetadata.hasOwnProperty(prop)) {
Expand Down
34 changes: 21 additions & 13 deletions packages/common-grpc/test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var duplexify = require('duplexify');
var extend = require('extend');
var googleProtoFiles = require('google-proto-files');
var grpc = require('grpc');
var grpcVersion = require('grpc/package.json').version;

This comment was marked as spam.

This comment was marked as spam.

var is = require('is');
var path = require('path');
var proxyquire = require('proxyquire');
Expand Down Expand Up @@ -273,33 +274,40 @@ describe('GrpcService', function() {
});

it('should default grpcMetadata to empty metadata', function() {
var fakeGrpcMetadata = {};
var fakeGrpcMetadata = {
'x-goog-api-client': [
'gl-node/' + process.versions.node,
'gccl/' + CONFIG.packageJson.version,
'grpc/' + grpcVersion].join(' ')

This comment was marked as spam.

This comment was marked as spam.

};

GrpcMetadataOverride = function() {
return fakeGrpcMetadata;
GrpcMetadataOverride = function() {};
GrpcMetadataOverride.prototype.add = function(prop, val) {
this[prop] = val;
};

var config = extend({}, CONFIG);
delete config.grpcMetadata;

var grpcService = new GrpcService(config, OPTIONS);
assert.strictEqual(grpcService.grpcMetadata, fakeGrpcMetadata);
assert.deepEqual(grpcService.grpcMetadata, fakeGrpcMetadata);
});

it('should create and localize grpcMetadata', function() {
var fakeGrpcMetadata = {
add: function(prop, value) {
assert.strictEqual(prop, Object.keys(CONFIG.grpcMetadata)[0]);
assert.strictEqual(value, CONFIG.grpcMetadata[prop]);
}
};
var fakeGrpcMetadata = extend({
'x-goog-api-client': [
'gl-node/' + process.versions.node,
'gccl/' + CONFIG.packageJson.version,
'grpc/' + grpcVersion].join(' ')
}, CONFIG.grpcMetadata);

GrpcMetadataOverride = function() {
return fakeGrpcMetadata;
GrpcMetadataOverride = function() {};
GrpcMetadataOverride.prototype.add = function(prop, val) {
this[prop] = val;
};

var grpcService = new GrpcService(CONFIG, OPTIONS);
assert.strictEqual(grpcService.grpcMetadata, fakeGrpcMetadata);
assert.deepEqual(grpcService.grpcMetadata, fakeGrpcMetadata);
});

it('should localize maxRetries', function() {
Expand Down