Added user-agent setting code, and a test for it

pull/2604/head
murgatroid99 10 years ago
parent 61e647819c
commit 198a1ad966
  1. 6
      src/node/src/client.js
  2. 10
      src/node/test/surface_test.js

@ -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);
@ -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;

@ -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;

Loading…
Cancel
Save