diff options
author | 2015-03-19 11:16:48 -0700 | |
---|---|---|
committer | 2015-03-19 11:16:48 -0700 | |
commit | e0f24dc2add401ecf970bff48ae592866d8a6af1 (patch) | |
tree | 44fb249bb21917124884bfda3f67d652a4d9bc49 /src/node/test/surface_test.js | |
parent | e023e98d9a2513f61a7dbf0555e54da7bbdbdfd1 (diff) |
Added a test for generic client and server constructors
Diffstat (limited to 'src/node/test/surface_test.js')
-rw-r--r-- | src/node/test/surface_test.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 6fae483e6c..96b47815e1 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -45,6 +45,8 @@ var math_proto = ProtoBuf.loadProtoFile(__dirname + '/../examples/math.proto'); var mathService = math_proto.lookup('math.Math'); +var capitalize = require('underscore.string/capitalize'); + describe('Surface server constructor', function() { it('Should fail with conflicting method names', function() { assert.throws(function() { @@ -75,6 +77,55 @@ describe('Surface server constructor', function() { }, /math.Math/); }); }); +describe('Generic client and server', function() { + function toString(val) { + return val.toString(); + } + function toBuffer(str) { + return new Buffer(str); + } + var string_service_attrs = { + 'capitalize' : { + path: '/string/capitalize', + requestStream: false, + responseStream: false, + requestSerialize: toBuffer, + requestDeserialize: toString, + responseSerialize: toBuffer, + responseDeserialize: toString + } + }; + describe('String client and server', function() { + var client; + var server; + before(function() { + var Server = grpc.makeGenericServerConstructor({ + string: string_service_attrs + }); + server = new Server({ + string: { + capitalize: function(call, callback) { + callback(null, capitalize(call.request)); + } + } + }); + var port = server.bind('localhost:0'); + server.listen(); + var Client = grpc.makeGenericClientConstructor(string_service_attrs); + client = new Client('localhost:' + port); + }); + after(function() { + server.shutdown(); + }); + it('Should respond with a capitalized string', function(done) { + client.capitalize('abc', function(err, response) { + assert.ifError(err); + assert.strictEqual(response, 'Abc'); + done(); + }); + }); + }); +}); describe('Cancelling surface client', function() { var client; var server; |