Skip to content

Commit

Permalink
test: remove files after test execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Sep 9, 2024
1 parent 39cc362 commit 0fc190a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
9 changes: 4 additions & 5 deletions packages/storage_client/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(() {
Expand All @@ -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];

Expand Down
80 changes: 48 additions & 32 deletions packages/storage_client/test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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',
Expand All @@ -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();
}
});
});

Expand Down

0 comments on commit 0fc190a

Please sign in to comment.