mirror of https://github.com/AMT-Cheif/drift.git
Test to ensure failing migration throws
This commit is contained in:
parent
424c2febda
commit
49f7dc059f
|
@ -8,9 +8,11 @@ export 'package:mockito/mockito.dart';
|
|||
|
||||
class MockExecutor extends Mock implements QueryExecutor {
|
||||
final MockTransactionExecutor transactions = MockTransactionExecutor();
|
||||
final OpeningDetails openingDetails;
|
||||
|
||||
var _opened = false;
|
||||
|
||||
MockExecutor() {
|
||||
MockExecutor([this.openingDetails]) {
|
||||
when(runSelect(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value([]);
|
||||
|
@ -36,9 +38,16 @@ class MockExecutor extends Mock implements QueryExecutor {
|
|||
return transactions;
|
||||
});
|
||||
|
||||
when(ensureOpen(any)).thenAnswer((i) {
|
||||
when(ensureOpen(any)).thenAnswer((i) async {
|
||||
if (!_opened && openingDetails != null) {
|
||||
_opened = true;
|
||||
return Future.value(true);
|
||||
await (i.positionalArguments.single as QueryExecutorUser)
|
||||
.beforeOpen(this, openingDetails);
|
||||
}
|
||||
|
||||
_opened = true;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
when(close()).thenAnswer((_) async {
|
||||
|
|
|
@ -84,4 +84,12 @@ void main() {
|
|||
|
||||
verify(executor.close());
|
||||
});
|
||||
|
||||
test('throws when migration fails', () async {
|
||||
final executor = MockExecutor(const OpeningDetails(null, 1));
|
||||
when(executor.runCustom(any, any)).thenAnswer((_) => Future.error('error'));
|
||||
|
||||
final db = TodoDb(executor);
|
||||
expect(db.customSelect('SELECT 1').getSingle(), throwsA('error'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue