Test to ensure failing migration throws

This commit is contained in:
Simon Binder 2020-04-16 17:32:20 +02:00
parent 424c2febda
commit 49f7dc059f
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 20 additions and 3 deletions

View File

@ -8,9 +8,11 @@ export 'package:mockito/mockito.dart';
class MockExecutor extends Mock implements QueryExecutor { class MockExecutor extends Mock implements QueryExecutor {
final MockTransactionExecutor transactions = MockTransactionExecutor(); final MockTransactionExecutor transactions = MockTransactionExecutor();
final OpeningDetails openingDetails;
var _opened = false; var _opened = false;
MockExecutor() { MockExecutor([this.openingDetails]) {
when(runSelect(any, any)).thenAnswer((_) { when(runSelect(any, any)).thenAnswer((_) {
assert(_opened); assert(_opened);
return Future.value([]); return Future.value([]);
@ -36,9 +38,16 @@ class MockExecutor extends Mock implements QueryExecutor {
return transactions; return transactions;
}); });
when(ensureOpen(any)).thenAnswer((i) { when(ensureOpen(any)).thenAnswer((i) async {
if (!_opened && openingDetails != null) {
_opened = true;
await (i.positionalArguments.single as QueryExecutorUser)
.beforeOpen(this, openingDetails);
}
_opened = true; _opened = true;
return Future.value(true);
return true;
}); });
when(close()).thenAnswer((_) async { when(close()).thenAnswer((_) async {

View File

@ -84,4 +84,12 @@ void main() {
verify(executor.close()); 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'));
});
} }