From 642bb7e62aab803ebbd9a8c06fc4b6251263190b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 21 Nov 2023 14:15:13 +0100 Subject: [PATCH] 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. --- test/fake_database.dart | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/test/fake_database.dart b/test/fake_database.dart index efc8f91b..779e9c5e 100644 --- a/test/fake_database.dart +++ b/test/fake_database.dart @@ -16,10 +16,7 @@ * along with this program. If not, see . */ -import 'dart:io'; -import 'dart:math'; - -import 'package:file/memory.dart'; +import 'package:file/local.dart'; import 'package:hive/hive.dart'; import 'package:matrix/matrix.dart'; @@ -29,16 +26,15 @@ Future getDatabase(Client? _) => getHiveCollectionsDatabase(_); bool hiveInitialized = false; Future getHiveCollectionsDatabase(Client? c) async { - final fileSystem = MemoryFileSystem(); - final testHivePath = - '${fileSystem.path}/build/.test_store/${Random().nextDouble()}'; + final testHivePath = await LocalFileSystem() + .systemTempDirectory + .createTemp('dart-sdk-tests-database'); if (!hiveInitialized) { - Directory(testHivePath).createSync(recursive: true); - Hive.init(testHivePath); + Hive.init(testHivePath.path); } final db = HiveCollectionsDatabase( 'unit_test.${c?.hashCode}', - testHivePath, + testHivePath.path, ); await db.open(); return db; @@ -47,11 +43,10 @@ Future getHiveCollectionsDatabase(Client? c) async { // ignore: deprecated_member_use_from_same_package Future getHiveDatabase(Client? c) async { if (!hiveInitialized) { - final fileSystem = MemoryFileSystem(); - final testHivePath = - '${fileSystem.path}/build/.test_store/${Random().nextDouble()}'; - Directory(testHivePath).createSync(recursive: true); - Hive.init(testHivePath); + final testHivePath = await LocalFileSystem() + .systemTempDirectory + .createTemp('dart-sdk-tests-database'); + Hive.init(testHivePath.path); hiveInitialized = true; } // ignore: deprecated_member_use_from_same_package