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 all commits
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 @@ -178,6 +178,12 @@ 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,
'grpc/' + require('grpc/package.json').version
].join(' '));

if (config.grpcMetadata) {
for (var prop in config.grpcMetadata) {
if (config.grpcMetadata.hasOwnProperty(prop)) {
Expand Down
32 changes: 19 additions & 13 deletions packages/common-grpc/test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ describe('GrpcService', function() {
};
var ROOT_DIR = '/root/dir';
var PROTO_FILE_PATH = 'filepath.proto';
var EXPECTED_API_CLIENT_HEADER = [
'gl-node/' + process.versions.node,
'gccl/' + CONFIG.packageJson.version,
'grpc/' + require('grpc/package.json').version
].join(' ');

var MOCK_GRPC_API = { google: {} };
MOCK_GRPC_API.google[CONFIG.service] = {};
Expand Down Expand Up @@ -273,33 +278,34 @@ describe('GrpcService', function() {
});

it('should default grpcMetadata to empty metadata', function() {
var fakeGrpcMetadata = {};
var fakeGrpcMetadata = {
'x-goog-api-client': EXPECTED_API_CLIENT_HEADER
};

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': EXPECTED_API_CLIENT_HEADER
}, 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