From 0fc190a1b84d34795a223167f942ce757256b5c4 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Mon, 9 Sep 2024 17:54:12 +0200 Subject: [PATCH] test: remove files after test execution --- packages/storage_client/test/basic_test.dart | 9 +-- packages/storage_client/test/client_test.dart | 80 +++++++++++-------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/packages/storage_client/test/basic_test.dart b/packages/storage_client/test/basic_test.dart index b1edc3d3..62080dc6 100644 --- a/packages/storage_client/test/basic_test.dart +++ b/packages/storage_client/test/basic_test.dart @@ -35,6 +35,10 @@ String get objectUrl => '$supabaseUrl/storage/v1/object'; void main() { late SupabaseStorageClient client; late CustomHttpClient customHttpClient = CustomHttpClient(); + tearDown(() { + final file = File('a.txt'); + if (file.existsSync()) file.deleteSync(); + }); group('Client with custom http client', () { setUp(() { @@ -48,11 +52,6 @@ void main() { ); }); - tearDown(() { - final file = File('a.txt'); - if (file.existsSync()) file.deleteSync(); - }); - test('should list buckets', () async { customHttpClient.response = [testBucketJson, testBucketJson]; diff --git a/packages/storage_client/test/client_test.dart b/packages/storage_client/test/client_test.dart index 65ccde92..ef415977 100644 --- a/packages/storage_client/test/client_test.dart +++ b/packages/storage_client/test/client_test.dart @@ -240,11 +240,15 @@ void main() { final downloadedFile = await File('${Directory.current.path}/public-image.jpg').create(); - await downloadedFile.writeAsBytes(bytesArray); - final size = await downloadedFile.length(); - final type = lookupMimeType(downloadedFile.path); - expect(size, isPositive); - expect(type, 'image/jpeg'); + try { + await downloadedFile.writeAsBytes(bytesArray); + final size = await downloadedFile.length(); + final type = lookupMimeType(downloadedFile.path); + expect(size, isPositive); + expect(type, 'image/jpeg'); + } finally { + await downloadedFile.delete(); + } }); test('will download an authenticated transformed file', () async { @@ -259,15 +263,19 @@ void main() { final downloadedFile = await File('${Directory.current.path}/private-image.jpg').create(); - await downloadedFile.writeAsBytes(bytesArray); - final size = await downloadedFile.length(); - final type = lookupMimeType( - downloadedFile.path, - headerBytes: downloadedFile.readAsBytesSync(), - ); - - expect(size, isPositive); - expect(type, 'image/jpeg'); + try { + await downloadedFile.writeAsBytes(bytesArray); + final size = await downloadedFile.length(); + final type = lookupMimeType( + downloadedFile.path, + headerBytes: downloadedFile.readAsBytesSync(), + ); + + expect(size, isPositive); + expect(type, 'image/jpeg'); + } finally { + await downloadedFile.delete(); + } }); test('will return the image as webp when the browser support it', () async { @@ -283,15 +291,19 @@ void main() { ); final downloadedFile = await File('${Directory.current.path}/webpimage').create(); - await downloadedFile.writeAsBytes(bytesArray); - final size = await downloadedFile.length(); - final type = lookupMimeType( - downloadedFile.path, - headerBytes: downloadedFile.readAsBytesSync(), - ); - - expect(size, isPositive); - expect(type, 'image/webp'); + try { + await downloadedFile.writeAsBytes(bytesArray); + final size = await downloadedFile.length(); + final type = lookupMimeType( + downloadedFile.path, + headerBytes: downloadedFile.readAsBytesSync(), + ); + + expect(size, isPositive); + expect(type, 'image/webp'); + } finally { + await downloadedFile.delete(); + } }); test('will return the original image format when format is origin', @@ -309,15 +321,19 @@ void main() { ); final downloadedFile = await File('${Directory.current.path}/jpegimage').create(); - await downloadedFile.writeAsBytes(bytesArray); - final size = await downloadedFile.length(); - final type = lookupMimeType( - downloadedFile.path, - headerBytes: downloadedFile.readAsBytesSync(), - ); - - expect(size, isPositive); - expect(type, 'image/jpeg'); + try { + await downloadedFile.writeAsBytes(bytesArray); + final size = await downloadedFile.length(); + final type = lookupMimeType( + downloadedFile.path, + headerBytes: downloadedFile.readAsBytesSync(), + ); + + expect(size, isPositive); + expect(type, 'image/jpeg'); + } finally { + await downloadedFile.delete(); + } }); });