forked from isoos/postgresql-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_handling_test.dart
71 lines (64 loc) · 1.91 KB
/
error_handling_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
import 'dart:async';
import 'package:postgres/postgres.dart';
import 'package:test/test.dart';
import 'docker.dart';
void main() {
withPostgresServer('error handling', (server) {
test('Reports stacktrace correctly', () async {
final conn = await server.newConnection();
addTearDown(() async => conn.close());
// Root connection query
try {
await conn.execute('SELECT hello');
fail('Should not reach');
} catch (e, st) {
expect(e.toString(), contains('column "hello" does not exist'));
expect(
st.toString(),
contains('test/error_handling_test.dart'),
);
}
// Root connection execute
try {
await conn.execute('DELETE FROM hello');
fail('Should not reach');
} catch (e, st) {
expect(e.toString(), contains('relation "hello" does not exist'));
expect(
st.toString(),
contains('test/error_handling_test.dart'),
);
}
// Inside transaction
try {
await conn.runTx((s) async {
await s.execute('SELECT hello');
fail('Should not reach');
});
} catch (e, st) {
expect(e.toString(), contains('column "hello" does not exist'));
expect(
st.toString(),
contains('test/error_handling_test.dart'),
);
}
});
test('TimeoutException', () async {
final c = await server.newConnection(queryMode: QueryMode.simple);
await c.execute('SET statement_timeout = 1000;');
await expectLater(
() => c.execute('SELECT pg_sleep(2);'),
throwsA(
allOf(
isA<TimeoutException>(),
isA<PgException>().having(
(e) => e.toString(),
'toString()',
'Severity.error 57014: canceling statement due to statement timeout',
),
),
),
);
});
});
}