mirror of https://github.com/AMT-Cheif/drift.git
Tests: Verify that an executor is open when used.
This commit is contained in:
parent
0ef56d6163
commit
4af370f0cb
|
@ -10,19 +10,40 @@ typedef Future<T> _EnsureOpenAction<T>(QueryExecutor e);
|
|||
|
||||
class MockExecutor extends Mock implements QueryExecutor {
|
||||
final MockTransactionExecutor transactions = MockTransactionExecutor();
|
||||
var _opened = false;
|
||||
|
||||
MockExecutor() {
|
||||
when(runSelect(any, any)).thenAnswer((_) => Future.value([]));
|
||||
when(runUpdate(any, any)).thenAnswer((_) => Future.value(0));
|
||||
when(runDelete(any, any)).thenAnswer((_) => Future.value(0));
|
||||
when(runInsert(any, any)).thenAnswer((_) => Future.value(0));
|
||||
when(runSelect(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value([]);
|
||||
});
|
||||
when(runUpdate(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value(0);
|
||||
});
|
||||
when(runDelete(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value(0);
|
||||
});
|
||||
when(runInsert(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value(0);
|
||||
});
|
||||
when(beginTransaction()).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return transactions;
|
||||
});
|
||||
|
||||
when(doWhenOpened(any)).thenAnswer((i) {
|
||||
_opened = true;
|
||||
final action = i.positionalArguments.single as _EnsureOpenAction;
|
||||
|
||||
return action(this);
|
||||
});
|
||||
|
||||
when(beginTransaction()).thenAnswer((_) => transactions);
|
||||
when(close()).thenAnswer((_) async {
|
||||
_opened = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ mixin SchemaParser on ParserBase {
|
|||
ifNotExists = true;
|
||||
}
|
||||
|
||||
final tableIdentifier = _consumeIdentifier('Expected a table name');
|
||||
final tableIdentifier =
|
||||
_consumeIdentifier('Expected a table name', lenient: true);
|
||||
|
||||
// we don't currently support CREATE TABLE x AS SELECT ... statements
|
||||
_consume(
|
||||
|
@ -213,7 +214,8 @@ mixin SchemaParser on ParserBase {
|
|||
|
||||
String _constraintNameOrNull() {
|
||||
if (_matchOne(TokenType.constraint)) {
|
||||
final name = _consumeIdentifier('Expect a name for the constraint here');
|
||||
final name = _consumeIdentifier('Expect a name for the constraint here',
|
||||
lenient: true);
|
||||
return name.identifier;
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue