forked from dart-lang/webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities_test.dart
81 lines (70 loc) · 2.35 KB
/
utilities_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2023 The Dart Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@Timeout(Duration(minutes: 1))
library;
import 'package:dwds/src/utilities/shared.dart';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'fixtures/context.dart';
void main() {
group('wrapInErrorHandlerAsync', () {
test('returns future success value if callback succeeds', () async {
Future<bool> successCallback() async {
await Future.delayed(Duration(milliseconds: 500));
return true;
}
final result =
await wrapInErrorHandlerAsync('successCallback', successCallback);
expect(result, equals(true));
});
test('throws RPCError if callback throws RPCError', () async {
Future<bool> rpcErrorCallback() async {
await Future.delayed(Duration(milliseconds: 500));
throw RPCError(
'rpcErrorCallback',
RPCErrorKind.kInvalidRequest.code,
'An error message',
);
}
await expectLater(
wrapInErrorHandlerAsync('rpcErrorCallback', rpcErrorCallback),
throwsRPCErrorWithMessage('An error message'),
);
});
test('throws SentinelException if callback throws SentinelException',
() async {
Future<bool> sentinelExceptionCallback() async {
await Future.delayed(Duration(milliseconds: 500));
throw SentinelException.parse(
'sentinelExceptionCallback',
{'message': 'a sentinel exception'},
);
}
await expectLater(
wrapInErrorHandlerAsync(
'sentinelExceptionCallback',
sentinelExceptionCallback,
),
throwsSentinelException,
);
});
test('throws RPCError if callback throws other error type', () async {
Future<bool> exceptionCallback() async {
await Future.delayed(Duration(milliseconds: 500));
throw Exception('An unexpected exception');
}
try {
await wrapInErrorHandlerAsync('exceptionCallback', exceptionCallback);
fail('RPCError not thrown.');
} catch (error) {
expect(
error,
isRPCErrorWithMessage(
'Unexpected DWDS error for exceptionCallback: Exception: An unexpected exception',
),
);
}
});
});
}