fix: in memory database is not actually in memory
Since we can't pass the fake filesystem to hive, instead we just store the database in a temporary directory.
This commit is contained in:
parent
ee14fb7116
commit
642bb7e62a
|
|
@ -16,10 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'dart:io';
|
import 'package:file/local.dart';
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:file/memory.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
@ -29,16 +26,15 @@ Future<DatabaseApi> getDatabase(Client? _) => getHiveCollectionsDatabase(_);
|
||||||
bool hiveInitialized = false;
|
bool hiveInitialized = false;
|
||||||
|
|
||||||
Future<HiveCollectionsDatabase> getHiveCollectionsDatabase(Client? c) async {
|
Future<HiveCollectionsDatabase> getHiveCollectionsDatabase(Client? c) async {
|
||||||
final fileSystem = MemoryFileSystem();
|
final testHivePath = await LocalFileSystem()
|
||||||
final testHivePath =
|
.systemTempDirectory
|
||||||
'${fileSystem.path}/build/.test_store/${Random().nextDouble()}';
|
.createTemp('dart-sdk-tests-database');
|
||||||
if (!hiveInitialized) {
|
if (!hiveInitialized) {
|
||||||
Directory(testHivePath).createSync(recursive: true);
|
Hive.init(testHivePath.path);
|
||||||
Hive.init(testHivePath);
|
|
||||||
}
|
}
|
||||||
final db = HiveCollectionsDatabase(
|
final db = HiveCollectionsDatabase(
|
||||||
'unit_test.${c?.hashCode}',
|
'unit_test.${c?.hashCode}',
|
||||||
testHivePath,
|
testHivePath.path,
|
||||||
);
|
);
|
||||||
await db.open();
|
await db.open();
|
||||||
return db;
|
return db;
|
||||||
|
|
@ -47,11 +43,10 @@ Future<HiveCollectionsDatabase> getHiveCollectionsDatabase(Client? c) async {
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
Future<FamedlySdkHiveDatabase> getHiveDatabase(Client? c) async {
|
Future<FamedlySdkHiveDatabase> getHiveDatabase(Client? c) async {
|
||||||
if (!hiveInitialized) {
|
if (!hiveInitialized) {
|
||||||
final fileSystem = MemoryFileSystem();
|
final testHivePath = await LocalFileSystem()
|
||||||
final testHivePath =
|
.systemTempDirectory
|
||||||
'${fileSystem.path}/build/.test_store/${Random().nextDouble()}';
|
.createTemp('dart-sdk-tests-database');
|
||||||
Directory(testHivePath).createSync(recursive: true);
|
Hive.init(testHivePath.path);
|
||||||
Hive.init(testHivePath);
|
|
||||||
hiveInitialized = true;
|
hiveInitialized = true;
|
||||||
}
|
}
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue