@@ -14,6 +14,7 @@ import 'package:drift_flutter/src/native.dart'
1414 show PingWithTimeout, hasConfiguredSqlite, portName;
1515import 'package:flutter/services.dart' ;
1616import 'package:flutter_test/flutter_test.dart' ;
17+ import 'package:path_provider/path_provider.dart' ;
1718import 'package:sqlite3/sqlite3.dart' ;
1819import 'package:test_descriptor/test_descriptor.dart' as d;
1920
@@ -28,6 +29,7 @@ void main() {
2829 return switch (call.method) {
2930 'getTemporaryDirectory' => d.sandbox,
3031 'getApplicationDocumentsDirectory' => d.path ('applications' ),
32+ 'getApplicationSupportDirectory' => d.path ('support' ),
3133 _ => throw UnsupportedError ('Unexpected path provider call: $call ' )
3234 };
3335 });
@@ -69,6 +71,35 @@ void main() {
6971 await database.close ();
7072 });
7173
74+ test ('can use custom database directory' , () async {
75+ final database = SimpleDatabase (driftDatabase (
76+ name: 'database' ,
77+ native : DriftNativeOptions (
78+ databaseDirectory: getApplicationSupportDirectory,
79+ ),
80+ ));
81+ await database.customSelect ('SELECT 1' ).get ();
82+
83+ expect (sqlite3.tempDirectory, d.sandbox);
84+ await d.dir ('support' , [
85+ d.FileDescriptor .binaryMatcher ('database.sqlite' , anything),
86+ ]).validate ();
87+ await database.close ();
88+ });
89+
90+ test ('forbids passing custom directory and custom path' , () async {
91+ expect (
92+ () => SimpleDatabase (driftDatabase (
93+ name: 'database' ,
94+ native : DriftNativeOptions (
95+ databasePath: () async => d.path ('my_dir/custom_file' ),
96+ databaseDirectory: getApplicationSupportDirectory,
97+ ),
98+ )),
99+ throwsAssertionError,
100+ );
101+ });
102+
72103 test ('can use custom temporary directory' , () async {
73104 final database = SimpleDatabase (driftDatabase (
74105 name: 'database' ,
@@ -147,6 +178,7 @@ void main() {
147178 final isolate = await Isolate .spawn ((_) {}, '' );
148179 isolate.kill ();
149180
181+ await pumpEventQueue (times: 1 );
150182 expect (await isolate.pingWithTimeout (), false );
151183 });
152184
0 commit comments