mirror of https://github.com/grpc/grpc-dart.git
Update Deps & Refactor
This commit is contained in:
parent
a2981c4f1d
commit
25ea43a435
|
@ -68,14 +68,19 @@ Future<int> main(List<String> args) async {
|
|||
help: 'The server host to claim to be connecting to, for use in TLS and '
|
||||
'HTTP/2 :authority header. If unspecified, the value of '
|
||||
'--server_host will be used.');
|
||||
argumentParser.addOption(_serverPortArgument, help: 'The server port to connect to. For example, "8080".');
|
||||
argumentParser.addOption(_serverPortArgument,
|
||||
help: 'The server port to connect to. For example, "8080".');
|
||||
argumentParser.addOption(_testCaseArgument,
|
||||
help: 'The name of the test case to execute. For example, "empty_unary".');
|
||||
help:
|
||||
'The name of the test case to execute. For example, "empty_unary".');
|
||||
argumentParser.addOption(_useTLSArgument,
|
||||
defaultsTo: 'false', help: 'Whether to use a plaintext or encrypted connection.');
|
||||
defaultsTo: 'false',
|
||||
help: 'Whether to use a plaintext or encrypted connection.');
|
||||
argumentParser.addOption(_useTestCAArgument,
|
||||
defaultsTo: 'false', help: 'Whether to replace platform root CAs with ca.pem as the CA root.');
|
||||
argumentParser.addOption(_defaultServiceAccountArgument, help: 'Email of the GCE default service account.');
|
||||
defaultsTo: 'false',
|
||||
help: 'Whether to replace platform root CAs with ca.pem as the CA root.');
|
||||
argumentParser.addOption(_defaultServiceAccountArgument,
|
||||
help: 'Email of the GCE default service account.');
|
||||
argumentParser.addOption(_oauthScopeArgument,
|
||||
help: 'OAuth scope. For example, '
|
||||
'"https://www.googleapis.com/auth/xapi.zoo".');
|
||||
|
@ -87,11 +92,14 @@ Future<int> main(List<String> args) async {
|
|||
late Tester testClient;
|
||||
try {
|
||||
testClient = Tester(
|
||||
serverHost: arguments[_serverHostArgument] ?? (throw 'Must specify --$_serverHostArgument'),
|
||||
serverHost: arguments[_serverHostArgument] ??
|
||||
(throw 'Must specify --$_serverHostArgument'),
|
||||
serverHostOverride: arguments[_serverHostOverrideArgument],
|
||||
serverPort: int.tryParse(arguments[_serverPortArgument] ?? (throw 'Must specify --$_serverPortArgument')) ??
|
||||
serverPort: int.tryParse(arguments[_serverPortArgument] ??
|
||||
(throw 'Must specify --$_serverPortArgument')) ??
|
||||
(throw 'Invalid port "${arguments[_serverPortArgument]}"'),
|
||||
testCase: arguments[_testCaseArgument] ?? (throw 'Must specify --$_testCaseArgument'),
|
||||
testCase: arguments[_testCaseArgument] ??
|
||||
(throw 'Must specify --$_testCaseArgument'),
|
||||
useTls: arguments[_useTLSArgument] == 'true',
|
||||
useTestCA: arguments[_useTestCAArgument] == 'true',
|
||||
defaultServiceAccount: arguments[_defaultServiceAccountArgument],
|
||||
|
|
|
@ -110,14 +110,16 @@ void main() {
|
|||
|
||||
test('Server returns error on unimplemented path', () async {
|
||||
harness
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Path /Test/NotFound not found')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unimplemented, 'Path /Test/NotFound not found')
|
||||
..sendRequestHeader('/Test/NotFound');
|
||||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
/// Returns a service method handler that verifies that awaiting the request
|
||||
/// throws a specific error.
|
||||
Future<int> Function(ServiceCall call, Future<int> request) expectError(expectedError) {
|
||||
Future<int> Function(ServiceCall call, Future<int> request) expectError(
|
||||
expectedError) {
|
||||
return expectAsync2((ServiceCall call, Future<int> request) async {
|
||||
try {
|
||||
final result = await request;
|
||||
|
@ -136,7 +138,8 @@ void main() {
|
|||
|
||||
/// Returns a service method handler that verifies that awaiting the request
|
||||
/// stream throws a specific error.
|
||||
Stream<int> Function(ServiceCall call, Stream<int> request) expectErrorStreaming(expectedError) {
|
||||
Stream<int> Function(ServiceCall call, Stream<int> request)
|
||||
expectErrorStreaming(expectedError) {
|
||||
return (ServiceCall call, Stream<int> request) async* {
|
||||
try {
|
||||
await for (var entry in request) {
|
||||
|
@ -156,16 +159,19 @@ void main() {
|
|||
|
||||
test('Server returns error on missing request for unary call', () async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('No request received'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('No request received'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'No request received')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..toServer.close();
|
||||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
test('Server returns error if multiple headers are received for unary call', () async {
|
||||
test('Server returns error if multiple headers are received for unary call',
|
||||
() async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('Expected request'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('Expected request'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Expected request')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..toServer.add(HeadersStreamMessage([]))
|
||||
|
@ -175,7 +181,8 @@ void main() {
|
|||
|
||||
test('Server returns error on too many requests for unary call', () async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('Too many requests'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('Too many requests'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Too many requests')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..sendData(dummyValue)
|
||||
|
@ -186,8 +193,10 @@ void main() {
|
|||
|
||||
test('Server returns request deserialization errors', () async {
|
||||
harness
|
||||
..service.bidirectionalHandler = expectErrorStreaming(GrpcError.internal('Error deserializing request: Failed'))
|
||||
..expectErrorResponse(StatusCode.internal, 'Error deserializing request: Failed')
|
||||
..service.bidirectionalHandler = expectErrorStreaming(
|
||||
GrpcError.internal('Error deserializing request: Failed'))
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Error deserializing request: Failed')
|
||||
..sendRequestHeader('/Test/RequestError')
|
||||
..sendData(dummyValue)
|
||||
..toServer.close();
|
||||
|
@ -196,8 +205,10 @@ void main() {
|
|||
|
||||
test('Server returns response serialization errors', () async {
|
||||
harness
|
||||
..service.bidirectionalHandler = expectErrorStreaming(GrpcError.internal('Error sending response: Failed'))
|
||||
..expectErrorResponse(StatusCode.internal, 'Error sending response: Failed')
|
||||
..service.bidirectionalHandler = expectErrorStreaming(
|
||||
GrpcError.internal('Error sending response: Failed'))
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Error sending response: Failed')
|
||||
..sendRequestHeader('/Test/ResponseError')
|
||||
..sendData(dummyValue)
|
||||
..sendData(dummyValue)
|
||||
|
@ -258,9 +269,12 @@ void main() {
|
|||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
test('Server returns error if request stream is closed before sending anything', () async {
|
||||
test(
|
||||
'Server returns error if request stream is closed before sending anything',
|
||||
() async {
|
||||
harness
|
||||
..expectErrorResponse(StatusCode.unavailable, 'Request stream closed unexpectedly')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unavailable, 'Request stream closed unexpectedly')
|
||||
..toServer.close();
|
||||
await harness.fromServer.done;
|
||||
});
|
||||
|
@ -291,7 +305,8 @@ void main() {
|
|||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
group('returns error if interceptor blocks request', () {
|
||||
|
@ -305,14 +320,16 @@ void main() {
|
|||
Future<void> doTest(Interceptor handler) async {
|
||||
harness
|
||||
..interceptor.handler = handler
|
||||
..expectErrorResponse(StatusCode.unauthenticated, 'Request is unauthenticated')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unauthenticated, 'Request is unauthenticated')
|
||||
..sendRequestHeader('/Test/Unary');
|
||||
|
||||
await harness.fromServer.done;
|
||||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
group('returns internal error if interceptor throws exception', () {
|
||||
|
@ -323,14 +340,16 @@ void main() {
|
|||
Future<void> doTest(Interceptor handler) async {
|
||||
harness
|
||||
..interceptor.handler = handler
|
||||
..expectErrorResponse(StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..sendRequestHeader('/Test/Unary');
|
||||
|
||||
await harness.fromServer.done;
|
||||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
test("don't fail if interceptor await 2 times", () async {
|
||||
|
@ -342,7 +361,8 @@ void main() {
|
|||
|
||||
harness
|
||||
..interceptor.handler = interceptor
|
||||
..expectErrorResponse(StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..sendData(1);
|
||||
|
||||
|
|
|
@ -110,14 +110,16 @@ void main() {
|
|||
|
||||
test('Server returns error on unimplemented path', () async {
|
||||
harness
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Path /Test/NotFound not found')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unimplemented, 'Path /Test/NotFound not found')
|
||||
..sendRequestHeader('/Test/NotFound');
|
||||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
/// Returns a service method handler that verifies that awaiting the request
|
||||
/// throws a specific error.
|
||||
Future<int> Function(ServiceCall call, Future<int> request) expectError(expectedError) {
|
||||
Future<int> Function(ServiceCall call, Future<int> request) expectError(
|
||||
expectedError) {
|
||||
return expectAsync2((ServiceCall call, Future<int> request) async {
|
||||
try {
|
||||
final result = await request;
|
||||
|
@ -136,7 +138,8 @@ void main() {
|
|||
|
||||
/// Returns a service method handler that verifies that awaiting the request
|
||||
/// stream throws a specific error.
|
||||
Stream<int> Function(ServiceCall call, Stream<int> request) expectErrorStreaming(expectedError) {
|
||||
Stream<int> Function(ServiceCall call, Stream<int> request)
|
||||
expectErrorStreaming(expectedError) {
|
||||
return (ServiceCall call, Stream<int> request) async* {
|
||||
try {
|
||||
await for (var entry in request) {
|
||||
|
@ -156,7 +159,8 @@ void main() {
|
|||
|
||||
test('Server returns error on missing request for unary call', () async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('No request received'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('No request received'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'No request received')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..toServer.close();
|
||||
|
@ -177,9 +181,11 @@ void main() {
|
|||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
test('Server returns error if multiple headers are received for unary call', () async {
|
||||
test('Server returns error if multiple headers are received for unary call',
|
||||
() async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('Expected request'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('Expected request'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Expected request')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..toServer.add(HeadersStreamMessage([]))
|
||||
|
@ -189,7 +195,8 @@ void main() {
|
|||
|
||||
test('Server returns error on too many requests for unary call', () async {
|
||||
harness
|
||||
..service.unaryHandler = expectError(GrpcError.unimplemented('Too many requests'))
|
||||
..service.unaryHandler =
|
||||
expectError(GrpcError.unimplemented('Too many requests'))
|
||||
..expectErrorResponse(StatusCode.unimplemented, 'Too many requests')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..sendData(dummyValue)
|
||||
|
@ -200,8 +207,10 @@ void main() {
|
|||
|
||||
test('Server returns request deserialization errors', () async {
|
||||
harness
|
||||
..service.bidirectionalHandler = expectErrorStreaming(GrpcError.internal('Error deserializing request: Failed'))
|
||||
..expectErrorResponse(StatusCode.internal, 'Error deserializing request: Failed')
|
||||
..service.bidirectionalHandler = expectErrorStreaming(
|
||||
GrpcError.internal('Error deserializing request: Failed'))
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Error deserializing request: Failed')
|
||||
..sendRequestHeader('/Test/RequestError')
|
||||
..sendData(dummyValue)
|
||||
..toServer.close();
|
||||
|
@ -210,8 +219,10 @@ void main() {
|
|||
|
||||
test('Server returns response serialization errors', () async {
|
||||
harness
|
||||
..service.bidirectionalHandler = expectErrorStreaming(GrpcError.internal('Error sending response: Failed'))
|
||||
..expectErrorResponse(StatusCode.internal, 'Error sending response: Failed')
|
||||
..service.bidirectionalHandler = expectErrorStreaming(
|
||||
GrpcError.internal('Error sending response: Failed'))
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Error sending response: Failed')
|
||||
..sendRequestHeader('/Test/ResponseError')
|
||||
..sendData(dummyValue)
|
||||
..sendData(dummyValue)
|
||||
|
@ -272,9 +283,12 @@ void main() {
|
|||
await harness.fromServer.done;
|
||||
});
|
||||
|
||||
test('Server returns error if request stream is closed before sending anything', () async {
|
||||
test(
|
||||
'Server returns error if request stream is closed before sending anything',
|
||||
() async {
|
||||
harness
|
||||
..expectErrorResponse(StatusCode.unavailable, 'Request stream closed unexpectedly')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unavailable, 'Request stream closed unexpectedly')
|
||||
..toServer.close();
|
||||
await harness.fromServer.done;
|
||||
});
|
||||
|
@ -305,7 +319,8 @@ void main() {
|
|||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
group('returns error if interceptor blocks request', () {
|
||||
|
@ -319,14 +334,16 @@ void main() {
|
|||
Future<void> doTest(Interceptor handler) async {
|
||||
harness
|
||||
..interceptor.handler = handler
|
||||
..expectErrorResponse(StatusCode.unauthenticated, 'Request is unauthenticated')
|
||||
..expectErrorResponse(
|
||||
StatusCode.unauthenticated, 'Request is unauthenticated')
|
||||
..sendRequestHeader('/Test/Unary');
|
||||
|
||||
await harness.fromServer.done;
|
||||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
group('returns internal error if interceptor throws exception', () {
|
||||
|
@ -337,14 +354,16 @@ void main() {
|
|||
Future<void> doTest(Interceptor handler) async {
|
||||
harness
|
||||
..interceptor.handler = handler
|
||||
..expectErrorResponse(StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..sendRequestHeader('/Test/Unary');
|
||||
|
||||
await harness.fromServer.done;
|
||||
}
|
||||
|
||||
test('with sync interceptor', () => doTest(interceptor));
|
||||
test('with async interceptor', () => doTest((call, method) async => interceptor(call, method)));
|
||||
test('with async interceptor',
|
||||
() => doTest((call, method) async => interceptor(call, method)));
|
||||
});
|
||||
|
||||
test("don't fail if interceptor await 2 times", () async {
|
||||
|
@ -356,7 +375,8 @@ void main() {
|
|||
|
||||
harness
|
||||
..interceptor.handler = interceptor
|
||||
..expectErrorResponse(StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..expectErrorResponse(
|
||||
StatusCode.internal, 'Exception: Reason is unknown')
|
||||
..sendRequestHeader('/Test/Unary')
|
||||
..sendData(1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue