Skip to content

Commit

Permalink
Added user-agent setting code, and a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Jul 21, 2015
1 parent 61e6478 commit 198a1ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/node/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var Readable = stream.Readable;
var Writable = stream.Writable;
var Duplex = stream.Duplex;
var util = require('util');
var version = require('../package.json').version;

util.inherits(ClientWritableStream, Writable);

Expand Down Expand Up @@ -517,7 +518,10 @@ function makeClientConstructor(methods, serviceName) {
callback(null, metadata);
};
}

if (!options) {
options = {};
}
options.GRPC_ARG_PRIMARY_USER_AGENT_STRING = 'grpc-node/' + version;
this.server_address = address.replace(/\/$/, '');
this.channel = new grpc.Channel(address, options);
this.auth_uri = this.server_address + '/' + serviceName;
Expand Down
10 changes: 10 additions & 0 deletions src/node/test/surface_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ describe('Echo metadata', function() {
});
call.end();
});
it('shows the correct user-agent string', function(done) {
var version = require('../package.json').version;
var call = client.unary({}, function(err, data) {
assert.ifError(err);
}, {key: ['value']});
call.on('metadata', function(metadata) {
assert(_.startsWith(metadata['user-agent'], 'grpc-node/' + version));
done();
});
});
});
describe('Other conditions', function() {
var client;
Expand Down

0 comments on commit 198a1ad

Please sign in to comment.