Skip to content

Missing stacktrace basic reproduction test #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dev_dependencies:
pedantic: ^1.0.0
test: ^1.3.0
coverage: any
docker_process: ^1.3.0
47 changes: 47 additions & 0 deletions test/docker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:io';

import 'package:docker_process/containers/postgres.dart';
import 'package:test/test.dart';

const _kContainerName = 'postgres-dart-test';

void usePostgresDocker() {
bool isGithubAction() => Platform.environment.containsKey('GITHUB_ACTION');

setUpAll(() async {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add a teardownAll that stops the container

if (isGithubAction()) {
// Postgres already running
return;
}

final isRunning = await _isPostgresContainerRunning();
if (isRunning) {
return;
}

await startPostgres(
name: _kContainerName,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice thing to have here, I haven't really thought that you'd match the CI's config, but it makes sense.

version: 'latest',
pgPort: 5432,
pgDatabase: 'dart_test',
pgUser: 'dart',
pgPassword: 'dart',
cleanup: true,
);
});

tearDownAll(() async {
if (isGithubAction()) {
return;
}
await Process.run('docker', ['stop', _kContainerName]);
});
}

Future<bool> _isPostgresContainerRunning() async {
final pr = await Process.run(
'docker',
['ps', '--format', '{{.Names}}'],
);
return pr.stdout.toString().split('\n').map((s) => s.trim()).contains(_kContainerName);
}
22 changes: 22 additions & 0 deletions test/error_handling_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:postgres/postgres.dart';
import 'package:test/test.dart';

import 'docker.dart';

void main() {
usePostgresDocker();

test('Reports stacktrace correctly', () async {
final conn = PostgreSQLConnection('localhost', 5432, 'dart_test', username: 'dart', password: 'dart');
await conn.open();
addTearDown(() async => conn.close());

try {
await conn.query('SELECT hello');
fail('Should not reach');
} catch (e, st) {
// TODO: This expectation fails
//expect(st.toString(), isNotEmpty);
}
});
}