Test variable bindings through isolate dialect

Regression test for #2894
This commit is contained in:
Simon Binder 2024-02-19 21:28:03 +01:00
parent 364450d26a
commit d7a26a6a9a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 39 additions and 0 deletions

View File

@ -240,6 +240,34 @@ void main() {
await testWith(DatabaseConnection(NativeDatabase.memory()));
});
});
test('uses correct dialect', () async {
// Regression test for https://github.com/simolus3/drift/issues/2894
final isolate = await DriftIsolate.spawn(() {
return NativeDatabase.memory()
.interceptWith(PretendDialectInterceptor(SqlDialect.postgres));
});
final database = TodoDb(await isolate.connect(singleClientMode: true));
addTearDown(database.close);
await database.transaction(() async {
await expectLater(
database.into(database.users).insertReturning(UsersCompanion.insert(
name: 'test user', profilePicture: Uint8List(0))),
throwsA(
isA<DriftRemoteException>().having(
(e) => e.remoteCause,
'remoteCause',
isA<SqliteException>().having(
(e) => e.causingStatement,
'causingStatement',
contains(r'VALUES ($1, $2)'),
),
),
),
);
});
});
}
void _runTests(FutureOr<DriftIsolate> Function() spawner, bool terminateIsolate,

View File

@ -100,3 +100,14 @@ class CustomTable extends Table with TableInfo<CustomTable, void> {
return;
}
}
class PretendDialectInterceptor extends QueryInterceptor {
final SqlDialect _dialect;
PretendDialectInterceptor(this._dialect);
@override
SqlDialect dialect(QueryExecutor executor) {
return _dialect;
}
}