Skip to content

Commit a3fe383

Browse files
Missing stacktrace basic reproduction test (isoos#14)
* WIP: Missing stacktrace basic reproduction test * Nitpicks
1 parent b43e6ac commit a3fe383

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dev_dependencies:
1616
pedantic: ^1.0.0
1717
test: ^1.3.0
1818
coverage: any
19+
docker_process: ^1.3.0

test/docker.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'dart:io';
2+
3+
import 'package:docker_process/containers/postgres.dart';
4+
import 'package:test/test.dart';
5+
6+
const _kContainerName = 'postgres-dart-test';
7+
8+
void usePostgresDocker() {
9+
bool isGithubAction() => Platform.environment.containsKey('GITHUB_ACTION');
10+
11+
setUpAll(() async {
12+
if (isGithubAction()) {
13+
// Postgres already running
14+
return;
15+
}
16+
17+
final isRunning = await _isPostgresContainerRunning();
18+
if (isRunning) {
19+
return;
20+
}
21+
22+
await startPostgres(
23+
name: _kContainerName,
24+
version: 'latest',
25+
pgPort: 5432,
26+
pgDatabase: 'dart_test',
27+
pgUser: 'dart',
28+
pgPassword: 'dart',
29+
cleanup: true,
30+
);
31+
});
32+
33+
tearDownAll(() async {
34+
if (isGithubAction()) {
35+
return;
36+
}
37+
await Process.run('docker', ['stop', _kContainerName]);
38+
});
39+
}
40+
41+
Future<bool> _isPostgresContainerRunning() async {
42+
final pr = await Process.run(
43+
'docker',
44+
['ps', '--format', '{{.Names}}'],
45+
);
46+
return pr.stdout.toString().split('\n').map((s) => s.trim()).contains(_kContainerName);
47+
}

test/error_handling_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:postgres/postgres.dart';
2+
import 'package:test/test.dart';
3+
4+
import 'docker.dart';
5+
6+
void main() {
7+
usePostgresDocker();
8+
9+
test('Reports stacktrace correctly', () async {
10+
final conn = PostgreSQLConnection('localhost', 5432, 'dart_test', username: 'dart', password: 'dart');
11+
await conn.open();
12+
addTearDown(() async => conn.close());
13+
14+
try {
15+
await conn.query('SELECT hello');
16+
fail('Should not reach');
17+
} catch (e, st) {
18+
// TODO: This expectation fails
19+
//expect(st.toString(), isNotEmpty);
20+
}
21+
});
22+
}

0 commit comments

Comments
 (0)