-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_utils.dart
More file actions
39 lines (35 loc) · 962 Bytes
/
test_utils.dart
File metadata and controls
39 lines (35 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'dart:io';
import 'package:sqlite_async/sqlite_async.dart';
import 'package:test_api/src/backend/invoker.dart';
Future<SqliteDatabase> setupDatabase({String? path}) async {
final db =
SqliteDatabase.withFactory(SqliteOpenFactory(path: path ?? dbPath()));
await db.initialize();
return db;
}
Future<void> cleanDb({required String path}) async {
try {
await File(path).delete();
} on PathNotFoundException {
// Not an issue
}
try {
await File("$path-shm").delete();
} on PathNotFoundException {
// Not an issue
}
try {
await File("$path-wal").delete();
} on PathNotFoundException {
// Not an issue
}
}
String dbPath() {
final test = Invoker.current!.liveTest;
var testName = test.test.name;
var testShortName =
testName.replaceAll(RegExp(r'[\s\./]'), '_').toLowerCase();
var dbName = "test-db/$testShortName.db";
Directory("test-db").createSync(recursive: false);
return dbName;
}