chore: Move the drift_offline_first to legacy in favor of Serverpod implementation (#32)
This commit is contained in:
parent
027aec5ed0
commit
cbc472523b
1 changed files with 13575 additions and 284 deletions
44
legacy/drift_offline_sync/test/utils/executor.dart
Normal file
44
legacy/drift_offline_sync/test/utils/executor.dart
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import 'package:drift/native.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_descriptor/test_descriptor.dart';
|
||||
|
||||
/// Sets the test executor for the SQLite3 database.
|
||||
///
|
||||
/// This is a file-based SQLite3 executor that is used for testing. It follows
|
||||
/// the same pattern as the `test_descriptor` package to ensure one executor is
|
||||
/// created for each test. The executor is closed once test ends.
|
||||
///
|
||||
/// After setting the test executor, the database can be accessed using the
|
||||
/// [testExecutor] getter.
|
||||
void setTestFileExecutor([String fileName = 'test.db']) {
|
||||
final databaseFile = file(fileName);
|
||||
final sqliteDatabase = sqlite3.open(databaseFile.io.path);
|
||||
final executor = NativeDatabase.opened(sqliteDatabase);
|
||||
_setTestExecutor(executor);
|
||||
}
|
||||
|
||||
/// The test executor for the SQLite3 database.
|
||||
///
|
||||
/// This is a memory-based SQLite3 executor that is used for testing. It follows
|
||||
/// the same pattern as the `test_descriptor` package to ensure one executor is
|
||||
/// created for each test. The executor is closed once test ends.
|
||||
NativeDatabase get testExecutor {
|
||||
if (_testExecutor != null) return _testExecutor!;
|
||||
final executor = NativeDatabase.memory();
|
||||
_setTestExecutor(executor);
|
||||
return executor;
|
||||
}
|
||||
|
||||
NativeDatabase? _testExecutor;
|
||||
|
||||
void _setTestExecutor(NativeDatabase executor) {
|
||||
_testExecutor = executor;
|
||||
|
||||
addTearDown(() async {
|
||||
final executor = _testExecutor;
|
||||
if (executor == null) return;
|
||||
_testExecutor = null;
|
||||
await executor.close();
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue