23 lines
970 B
Dart
23 lines
970 B
Dart
import 'dart:ffi';
|
|||
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:cookit/src/database/database.dart';
|
||
|
|
import 'package:drift/drift.dart';
|
||
|
|
import 'package:drift/native.dart';
|
||
|
|
import 'package:sqlite3/open.dart';
|
||
|
|
|
||
|
|
/// An in-memory database for tests, or one in [file] to test migrations. On
|
||
|
|
/// Windows hosts the sqlite3 library comes from COOKIT_SQLITE_DLL if set,
|
||
|
|
/// otherwise from the system's winsqlite3.dll.
|
||
|
|
AppDatabase testDatabase({File? file}) {
|
||
|
|
if (Platform.isWindows) {
|
||
|
|
open.overrideFor(OperatingSystem.windows, () {
|
||
|
|
final custom = Platform.environment['COOKIT_SQLITE_DLL'];
|
||
|
|
return DynamicLibrary.open(custom ?? 'winsqlite3.dll');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
||
|
|
final executor = file == null ? NativeDatabase.memory() : NativeDatabase(file);
|
||
|
|
// Synchronous stream teardown keeps widget tests from hanging on pending timers.
|
||
|
|
return AppDatabase(DatabaseConnection(executor, closeStreamsSynchronously: true));
|
||
|
|
}
|