Skip to content

Commit b802b88

Browse files
author
Kinpert
committed
fix: Unit tests JsonCacheSafeLocalStorage while allocating a temporary directory
1 parent 7a724b6 commit b802b88

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test/json_cache_safe_local_storage_test.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:io';
2+
23
import 'package:flutter_test/flutter_test.dart';
34
import 'package:json_cache/src/json_cache_safe_local_storage.dart';
45
import 'package:safe_local_storage/safe_local_storage.dart';
@@ -109,6 +110,16 @@ void main() {
109110
// Check for multiple data.
110111
expect(await jsonCacheSafeLocalStorage.contains(profKey), true);
111112
expect(await jsonCacheSafeLocalStorage.contains(prefKey), true);
113+
114+
// Remove data from the cache.
115+
await jsonCacheSafeLocalStorage.remove(profKey);
116+
expect(await jsonCacheSafeLocalStorage.contains(profKey), false);
117+
expect(await jsonCacheSafeLocalStorage.contains(prefKey), true);
118+
119+
// Remove data from the cache.
120+
await jsonCacheSafeLocalStorage.remove(prefKey);
121+
expect(await jsonCacheSafeLocalStorage.contains(profKey), false);
122+
expect(await jsonCacheSafeLocalStorage.contains(prefKey), false);
112123
},
113124
);
114125

@@ -119,12 +130,15 @@ void main() {
119130
await jsonCacheSafeLocalStorage.refresh(profKey, profData);
120131
await jsonCacheSafeLocalStorage.refresh(prefKey, prefData);
121132

122-
// Clear it.
133+
// Clear it. All data should be deleted with the file.
123134
await jsonCacheSafeLocalStorage.clear();
124135

125136
// No data should remain in the cache.
126137
final cachedValue = await jsonCacheSafeLocalStorage.value(profKey);
127138
expect(cachedValue, isNull);
139+
140+
// Insert a single piece of data into the cache. This refresh avoids errors on operational systems.
141+
await jsonCacheSafeLocalStorage.refresh(profKey, profData);
128142
},
129143
);
130144
},
@@ -133,7 +147,6 @@ void main() {
133147
tearDown(
134148
() async {
135149
await storage.delete();
136-
await tempDir.delete_();
137150
},
138151
);
139152
}

0 commit comments

Comments
 (0)