Skip to content

Commit 0fc190a

Browse files
committed
test: remove files after test execution
1 parent 39cc362 commit 0fc190a

File tree

2 files changed

+52
-37
lines changed

2 files changed

+52
-37
lines changed

packages/storage_client/test/basic_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ String get objectUrl => '$supabaseUrl/storage/v1/object';
3535
void main() {
3636
late SupabaseStorageClient client;
3737
late CustomHttpClient customHttpClient = CustomHttpClient();
38+
tearDown(() {
39+
final file = File('a.txt');
40+
if (file.existsSync()) file.deleteSync();
41+
});
3842

3943
group('Client with custom http client', () {
4044
setUp(() {
@@ -48,11 +52,6 @@ void main() {
4852
);
4953
});
5054

51-
tearDown(() {
52-
final file = File('a.txt');
53-
if (file.existsSync()) file.deleteSync();
54-
});
55-
5655
test('should list buckets', () async {
5756
customHttpClient.response = [testBucketJson, testBucketJson];
5857

packages/storage_client/test/client_test.dart

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,15 @@ void main() {
240240

241241
final downloadedFile =
242242
await File('${Directory.current.path}/public-image.jpg').create();
243-
await downloadedFile.writeAsBytes(bytesArray);
244-
final size = await downloadedFile.length();
245-
final type = lookupMimeType(downloadedFile.path);
246-
expect(size, isPositive);
247-
expect(type, 'image/jpeg');
243+
try {
244+
await downloadedFile.writeAsBytes(bytesArray);
245+
final size = await downloadedFile.length();
246+
final type = lookupMimeType(downloadedFile.path);
247+
expect(size, isPositive);
248+
expect(type, 'image/jpeg');
249+
} finally {
250+
await downloadedFile.delete();
251+
}
248252
});
249253

250254
test('will download an authenticated transformed file', () async {
@@ -259,15 +263,19 @@ void main() {
259263

260264
final downloadedFile =
261265
await File('${Directory.current.path}/private-image.jpg').create();
262-
await downloadedFile.writeAsBytes(bytesArray);
263-
final size = await downloadedFile.length();
264-
final type = lookupMimeType(
265-
downloadedFile.path,
266-
headerBytes: downloadedFile.readAsBytesSync(),
267-
);
268-
269-
expect(size, isPositive);
270-
expect(type, 'image/jpeg');
266+
try {
267+
await downloadedFile.writeAsBytes(bytesArray);
268+
final size = await downloadedFile.length();
269+
final type = lookupMimeType(
270+
downloadedFile.path,
271+
headerBytes: downloadedFile.readAsBytesSync(),
272+
);
273+
274+
expect(size, isPositive);
275+
expect(type, 'image/jpeg');
276+
} finally {
277+
await downloadedFile.delete();
278+
}
271279
});
272280

273281
test('will return the image as webp when the browser support it', () async {
@@ -283,15 +291,19 @@ void main() {
283291
);
284292
final downloadedFile =
285293
await File('${Directory.current.path}/webpimage').create();
286-
await downloadedFile.writeAsBytes(bytesArray);
287-
final size = await downloadedFile.length();
288-
final type = lookupMimeType(
289-
downloadedFile.path,
290-
headerBytes: downloadedFile.readAsBytesSync(),
291-
);
292-
293-
expect(size, isPositive);
294-
expect(type, 'image/webp');
294+
try {
295+
await downloadedFile.writeAsBytes(bytesArray);
296+
final size = await downloadedFile.length();
297+
final type = lookupMimeType(
298+
downloadedFile.path,
299+
headerBytes: downloadedFile.readAsBytesSync(),
300+
);
301+
302+
expect(size, isPositive);
303+
expect(type, 'image/webp');
304+
} finally {
305+
await downloadedFile.delete();
306+
}
295307
});
296308

297309
test('will return the original image format when format is origin',
@@ -309,15 +321,19 @@ void main() {
309321
);
310322
final downloadedFile =
311323
await File('${Directory.current.path}/jpegimage').create();
312-
await downloadedFile.writeAsBytes(bytesArray);
313-
final size = await downloadedFile.length();
314-
final type = lookupMimeType(
315-
downloadedFile.path,
316-
headerBytes: downloadedFile.readAsBytesSync(),
317-
);
318-
319-
expect(size, isPositive);
320-
expect(type, 'image/jpeg');
324+
try {
325+
await downloadedFile.writeAsBytes(bytesArray);
326+
final size = await downloadedFile.length();
327+
final type = lookupMimeType(
328+
downloadedFile.path,
329+
headerBytes: downloadedFile.readAsBytesSync(),
330+
);
331+
332+
expect(size, isPositive);
333+
expect(type, 'image/jpeg');
334+
} finally {
335+
await downloadedFile.delete();
336+
}
321337
});
322338
});
323339

0 commit comments

Comments
 (0)