Fix postgres tests

This commit is contained in:
Simon Binder 2023-10-22 00:36:07 +02:00
parent 0e69252406
commit 61bd7f5ec2
6 changed files with 18 additions and 13 deletions

View File

@ -188,7 +188,7 @@ jobs:
working-directory: extras/drift_postgres
run: |
dart pub upgrade
dart test
dart test -j 1
- name: MariaDB integration tests
working-directory: extras/drift_mariadb
continue-on-error: true

View File

@ -26,6 +26,11 @@ void main() async {
username: 'postgres',
password: 'postgres',
),
sessionSettings: SessionSettings(
// If you expect to talk to a Postgres database over a public connection,
// please use SslMode.verifyFull instead.
sslMode: SslMode.disable,
),
);
final driftDatabase = MyDatabase(pgDatabase);

View File

@ -38,4 +38,4 @@ To test this package, first run
docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres
```
It can then be tested with `dart test`.
It can then be tested with `dart test -j 1` (concurrency needs to be disabled since tests are using the same database).

View File

@ -26,6 +26,11 @@ void main() async {
username: 'postgres',
password: 'postgres',
),
sessionSettings: pg.SessionSettings(
// If you expect to talk to a Postgres database over a public connection,
// please use SslMode.verifyFull instead.
sslMode: pg.SslMode.disable,
),
logStatements: true,
));

View File

@ -18,11 +18,12 @@ class PgExecutor extends TestExecutor {
username: 'postgres',
password: 'postgres',
),
sessionSettings: pg.SessionSettings(sslMode: pg.SslMode.disable),
));
}
@override
Future clearDatabaseAndClose(Database db) async {
Future clearDatabaseAndClose(GeneratedDatabase db) async {
await db.customStatement('DROP SCHEMA public CASCADE;');
await db.customStatement('CREATE SCHEMA public;');
await db.customStatement('GRANT ALL ON SCHEMA public TO postgres;');

View File

@ -5,24 +5,18 @@ import 'package:test/test.dart';
import 'package:uuid/uuid.dart';
import '../example/main.dart';
import 'drift_postgres_test.dart';
void main() {
final database = DriftPostgresDatabase(PgDatabase(
endpoint: pg.Endpoint(
host: 'localhost',
database: 'postgres',
username: 'postgres',
password: 'postgres',
),
));
final executor = PgExecutor();
final database = DriftPostgresDatabase(executor.createConnection());
setUpAll(() async {
await database.users.insertOne(UsersCompanion.insert(name: 'test user'));
});
tearDownAll(() async {
await database.users.deleteAll();
await database.close();
await executor.clearDatabaseAndClose(database);
});
group('custom types pass through', () {