diff options
Diffstat (limited to 'src/node/test')
-rw-r--r-- | src/node/test/call_test.js | 4 | ||||
-rw-r--r-- | src/node/test/common_test.js | 21 | ||||
-rw-r--r-- | src/node/test/constant_test.js | 131 | ||||
-rw-r--r-- | src/node/test/end_to_end_test.js | 17 | ||||
-rw-r--r-- | src/node/test/surface_test.js | 42 |
5 files changed, 41 insertions, 174 deletions
diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js index eb268603ea..f25268e8e6 100644 --- a/src/node/test/call_test.js +++ b/src/node/test/call_test.js @@ -35,6 +35,7 @@ var assert = require('assert'); var grpc = require('../src/grpc_extension'); +var constants = require('../src/constants'); /** * Helper function to return an absolute deadline given a relative timeout in @@ -120,7 +121,8 @@ describe('call', function() { var batch = {}; batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; call.startBatch(batch, function(err, response) { - assert.strictEqual(response.status.code, grpc.status.DEADLINE_EXCEEDED); + assert.strictEqual(response.status.code, + constants.status.DEADLINE_EXCEEDED); done(); }); }); diff --git a/src/node/test/common_test.js b/src/node/test/common_test.js index e1ce864f97..b7c2c6a8d6 100644 --- a/src/node/test/common_test.js +++ b/src/node/test/common_test.js @@ -37,16 +37,15 @@ var assert = require('assert'); var _ = require('lodash'); var common = require('../src/common'); -var protobuf_js_6_common = require('../src/protobuf_js_6_common'); +var protobuf_js_5_common = require('../src/protobuf_js_5_common'); -var serializeCls = protobuf_js_6_common.serializeCls; -var deserializeCls = protobuf_js_6_common.deserializeCls; +var serializeCls = protobuf_js_5_common.serializeCls; +var deserializeCls = protobuf_js_5_common.deserializeCls; var ProtoBuf = require('protobufjs'); -var messages_proto = new ProtoBuf.Root(); -messages_proto = messages_proto.loadSync( - __dirname + '/test_messages.proto', {keepCase: true}).resolveAll(); +var messages_proto = ProtoBuf.loadProtoFile( + __dirname + '/test_messages.proto').build(); var default_options = common.defaultGrpcOptions; @@ -101,6 +100,7 @@ describe('Proto message long int serialize and deserialize', function() { var longNumDeserialize = deserializeCls(messages_proto.LongValues, num_options); var serialized = longSerialize({int_64: pos_value}); + console.log(longDeserialize(serialized)); assert.strictEqual(typeof longDeserialize(serialized).int_64, 'string'); /* With the longsAsStrings option disabled, long values are represented as * objects with 3 keys: low, high, and unsigned */ @@ -136,7 +136,8 @@ describe('Proto message bytes serialize and deserialize', function() { var serialized = sequenceSerialize({repeated_field: [10]}); assert.strictEqual(expected_serialize.compare(serialized), 0); }); - it('should deserialize packed or unpacked repeated', function() { + // This tests a bug that was fixed in Protobuf.js 6 + it.skip('should deserialize packed or unpacked repeated', function() { var expectedDeserialize = { bytes_field: new Buffer(''), repeated_field: [10] @@ -155,7 +156,8 @@ describe('Proto message bytes serialize and deserialize', function() { assert.deepEqual(unpackedDeserialized, expectedDeserialize); }); }); -describe('Proto message oneof serialize and deserialize', function() { +// This tests a bug that was fixed in Protobuf.js 6 +describe.skip('Proto message oneof serialize and deserialize', function() { var oneofSerialize = serializeCls(messages_proto.OneOfValues); var oneofDeserialize = deserializeCls( messages_proto.OneOfValues, default_options); @@ -193,7 +195,8 @@ describe('Proto message enum serialize and deserialize', function() { assert.deepEqual(enumDeserialize(nameSerialized), enumDeserialize(numberSerialized)); }); - it('Should deserialize as a string the enumsAsStrings option', function() { + // This tests a bug that was fixed in Protobuf.js 6 + it.skip('Should correctly handle the enumsAsStrings option', function() { var serialized = enumSerialize({enum_value: 'TWO'}); var nameDeserialized = enumDeserialize(serialized); var numberDeserialized = enumIntDeserialize(serialized); diff --git a/src/node/test/constant_test.js b/src/node/test/constant_test.js deleted file mode 100644 index 414b1ac9c0..0000000000 --- a/src/node/test/constant_test.js +++ /dev/null @@ -1,131 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -'use strict'; - -var assert = require('assert'); -var grpc = require('../src/grpc_extension'); - -/** - * List of all status names - * @const - * @type {Array.<string>} - */ -var statusNames = [ - 'OK', - 'CANCELLED', - 'UNKNOWN', - 'INVALID_ARGUMENT', - 'DEADLINE_EXCEEDED', - 'NOT_FOUND', - 'ALREADY_EXISTS', - 'PERMISSION_DENIED', - 'UNAUTHENTICATED', - 'RESOURCE_EXHAUSTED', - 'FAILED_PRECONDITION', - 'ABORTED', - 'OUT_OF_RANGE', - 'UNIMPLEMENTED', - 'INTERNAL', - 'UNAVAILABLE', - 'DATA_LOSS' -]; - -/** - * List of all call error names - * @const - * @type {Array.<string>} - */ -var callErrorNames = [ - 'OK', - 'ERROR', - 'NOT_ON_SERVER', - 'NOT_ON_CLIENT', - 'ALREADY_INVOKED', - 'NOT_INVOKED', - 'ALREADY_FINISHED', - 'TOO_MANY_OPERATIONS', - 'INVALID_FLAGS' -]; - -/** - * List of all propagate flag names - * @const - * @type {Array.<string>} - */ -var propagateFlagNames = [ - 'DEADLINE', - 'CENSUS_STATS_CONTEXT', - 'CENSUS_TRACING_CONTEXT', - 'CANCELLATION', - 'DEFAULTS' -]; -/* - * List of all connectivity state names - * @const - * @type {Array.<string>} - */ -var connectivityStateNames = [ - 'IDLE', - 'CONNECTING', - 'READY', - 'TRANSIENT_FAILURE', - 'FATAL_FAILURE' -]; - -describe('constants', function() { - it('should have all of the status constants', function() { - for (var i = 0; i < statusNames.length; i++) { - assert(grpc.status.hasOwnProperty(statusNames[i]), - 'status missing: ' + statusNames[i]); - } - }); - it('should have all of the call errors', function() { - for (var i = 0; i < callErrorNames.length; i++) { - assert(grpc.callError.hasOwnProperty(callErrorNames[i]), - 'call error missing: ' + callErrorNames[i]); - } - }); - it('should have all of the propagate flags', function() { - for (var i = 0; i < propagateFlagNames.length; i++) { - assert(grpc.propagate.hasOwnProperty(propagateFlagNames[i]), - 'call error missing: ' + propagateFlagNames[i]); - } - }); - it('should have all of the connectivity states', function() { - for (var i = 0; i < connectivityStateNames.length; i++) { - assert(grpc.connectivityState.hasOwnProperty(connectivityStateNames[i]), - 'connectivity status missing: ' + connectivityStateNames[i]); - } - }); -}); diff --git a/src/node/test/end_to_end_test.js b/src/node/test/end_to_end_test.js index f127a41de9..af455e2716 100644 --- a/src/node/test/end_to_end_test.js +++ b/src/node/test/end_to_end_test.js @@ -35,6 +35,7 @@ var assert = require('assert'); var grpc = require('../src/grpc_extension'); +var constants = require('../src/constants'); /** * This is used for testing functions with multiple asynchronous calls that @@ -90,7 +91,7 @@ describe('end-to-end', function() { client_close: true, metadata: {}, status: { - code: grpc.status.OK, + code: constants.status.OK, details: status_text, metadata: {} } @@ -107,7 +108,7 @@ describe('end-to-end', function() { server_batch[grpc.opType.SEND_INITIAL_METADATA] = {}; server_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = { metadata: {}, - code: grpc.status.OK, + code: constants.status.OK, details: status_text }; server_batch[grpc.opType.RECV_CLOSE_ON_SERVER] = true; @@ -141,7 +142,7 @@ describe('end-to-end', function() { send_metadata: true, client_close: true, metadata: {server_key: ['server_value']}, - status: {code: grpc.status.OK, + status: {code: constants.status.OK, details: status_text, metadata: {}} }); @@ -161,7 +162,7 @@ describe('end-to-end', function() { }; server_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = { metadata: {}, - code: grpc.status.OK, + code: constants.status.OK, details: status_text }; server_batch[grpc.opType.RECV_CLOSE_ON_SERVER] = true; @@ -198,7 +199,7 @@ describe('end-to-end', function() { assert.deepEqual(response.metadata, {}); assert(response.send_message); assert.strictEqual(response.read.toString(), reply_text); - assert.deepEqual(response.status, {code: grpc.status.OK, + assert.deepEqual(response.status, {code: constants.status.OK, details: status_text, metadata: {}}); done(); @@ -220,7 +221,7 @@ describe('end-to-end', function() { response_batch[grpc.opType.SEND_MESSAGE] = new Buffer(reply_text); response_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = { metadata: {}, - code: grpc.status.OK, + code: constants.status.OK, details: status_text }; response_batch[grpc.opType.RECV_CLOSE_ON_SERVER] = true; @@ -260,7 +261,7 @@ describe('end-to-end', function() { send_message: true, client_close: true, status: { - code: grpc.status.OK, + code: constants.status.OK, details: status_text, metadata: {} } @@ -290,7 +291,7 @@ describe('end-to-end', function() { end_batch[grpc.opType.RECV_CLOSE_ON_SERVER] = true; end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = { metadata: {}, - code: grpc.status.OK, + code: constants.status.OK, details: status_text }; server_call.startBatch(end_batch, function(err, response) { diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 783028fa99..d2f0511af2 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -43,9 +43,8 @@ var ProtoBuf = require('protobufjs'); var grpc = require('..'); -var math_proto = new ProtoBuf.Root(); -math_proto = math_proto.loadSync(__dirname + - '/../../proto/math/math.proto', {keepCase: true}); +var math_proto = ProtoBuf.loadProtoFile(__dirname + + '/../../proto/math/math.proto'); var mathService = math_proto.lookup('math.Math'); var mathServiceAttrs = grpc.loadObject( @@ -332,9 +331,7 @@ describe('Echo service', function() { var server; var client; before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/echo_service.proto', - {keepCase: true}); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto'); var echo_service = test_proto.lookup('EchoService'); var Client = grpc.loadObject(echo_service); server = new grpc.Server(); @@ -357,6 +354,13 @@ describe('Echo service', function() { done(); }); }); + it('Should convert an undefined argument to default values', function(done) { + client.echo(undefined, function(error, response) { + assert.ifError(error); + assert.deepEqual(response, {value: '', value2: 0}); + done(); + }); + }); }); describe('Generic client and server', function() { function toString(val) { @@ -457,9 +461,7 @@ describe('Echo metadata', function() { var server; var metadata; before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/test_service.proto', - {keepCase: true}); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); var test_service = test_proto.lookup('TestService'); var Client = grpc.loadObject(test_service); server = new grpc.Server(); @@ -560,9 +562,7 @@ describe('Client malformed response handling', function() { var client; var badArg = new Buffer([0xFF]); before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/test_service.proto', - {keepCase: true}); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); var test_service = test_proto.lookup('TestService'); var malformed_test_service = { unary: { @@ -669,9 +669,7 @@ describe('Server serialization failure handling', function() { var client; var server; before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/test_service.proto', - {keepCase: true}); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); var test_service = test_proto.lookup('TestService'); var malformed_test_service = { unary: { @@ -772,16 +770,13 @@ describe('Server serialization failure handling', function() { }); }); describe('Other conditions', function() { - var test_service; var Client; var client; var server; var port; before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/test_service.proto', - {keepCase: true}); - test_service = test_proto.lookup('TestService'); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); + var test_service = test_proto.lookup('TestService'); Client = grpc.loadObject(test_service); server = new grpc.Server(); var trailer_metadata = new grpc.Metadata(); @@ -1121,15 +1116,12 @@ describe('Call propagation', function() { var proxy; var proxy_impl; - var test_service; var Client; var client; var server; before(function() { - var test_proto = new ProtoBuf.Root(); - test_proto = test_proto.loadSync(__dirname + '/test_service.proto', - {keepCase: true}); - test_service = test_proto.lookup('TestService'); + var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); + var test_service = test_proto.lookup('TestService'); server = new grpc.Server(); Client = grpc.loadObject(test_service); server.addService(Client.service, { |