Skip to content

Commit

Permalink
fixing up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed Oct 28, 2024
1 parent ee0bac0 commit 530140a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,39 @@ void main() {
testWidgets('multi bucket', (_) async {
final mainBucket =
StorageBucket.fromOutputs('Storage Integ Test main bucket');
final secondaryBucket = StorageBucket.fromOutputs(
'Storage Integ Test secondary bucket',
);
await Amplify.Storage.uploadData(
path: StoragePath.fromString(publicPath),
data: StorageDataPayload.bytes(bytesData),
bucket: secondaryBucket,
).result;

// TODO(equartey): Add download check for secondary bucket when upload supports multibucket
final downloadResult = await Amplify.Storage.downloadData(
path: StoragePath.fromIdentityId(
(identityId) => 'private/$identityId/$identityName',
),
path: StoragePath.fromString(publicPath),
options: StorageDownloadDataOptions(bucket: mainBucket),
).result;
expect(downloadResult.bytes, identityData);
expect(
downloadResult.bytes,
bytesData,
);
expect(
downloadResult.downloadedItem.path,
'private/$userIdentityId/$identityName',
publicPath,
);

final downloadSecondaryResult = await Amplify.Storage.downloadData(
path: StoragePath.fromString(publicPath),
options: StorageDownloadDataOptions(bucket: secondaryBucket),
).result;
expect(
downloadSecondaryResult.bytes,
bytesData,
);
expect(
downloadSecondaryResult.downloadedItem.path,
publicPath,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ void main() {

testWidgets('uploads to multiple buckets', (_) async {
final fileId = uuid();
final path =
StoragePath.fromString('public/multi-bucket-upload-file-$fileId');
final path = 'public/multi-bucket-upload-file-$fileId';
final storagePath = StoragePath.fromString(path);
const content = 'upload file';
final data = content.codeUnits;
final filePath = await createFile(path: fileId, content: content);
addTearDownMultiBucket(
path,
storagePath,
[mainBucket, secondaryBucket],
);
// main bucket
final mainResult = await Amplify.Storage.uploadFile(
localFile: AWSFile.fromPath(filePath),
path: path,
path: storagePath,
options: StorageUploadFileOptions(
pluginOptions: const S3UploadFilePluginOptions(
useAccelerateEndpoint: true,
Expand All @@ -253,7 +253,7 @@ void main() {
expect(mainResult.uploadedItem.path, path);

final downloadMainResult = await Amplify.Storage.downloadData(
path: path,
path: storagePath,
options: StorageDownloadDataOptions(
bucket: mainBucket,
),
Expand All @@ -263,7 +263,7 @@ void main() {
// secondary bucket
final secondaryResult = await Amplify.Storage.uploadFile(
localFile: AWSFile.fromPath(filePath),
path: path,
path: storagePath,
options: StorageUploadFileOptions(
pluginOptions: const S3UploadFilePluginOptions(
useAccelerateEndpoint: true,
Expand All @@ -274,17 +274,24 @@ void main() {
expect(secondaryResult.uploadedItem.path, path);

final downloadSecondaryResult = await Amplify.Storage.downloadData(
path: path,
path: storagePath,
options: StorageDownloadDataOptions(
bucket: secondaryBucket,
),
).result;
expect(downloadSecondaryResult.bytes, data);

expect(
await objectExistsInBuckets(
path,
[mainBucket, secondaryBucket],
await objectExists(
storagePath,
bucket: mainBucket,
),
true,
);
expect(
await objectExists(
storagePath,
bucket: secondaryBucket,
),
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import 'package:flutter_test/flutter_test.dart';
final _logger = AmplifyLogger().createChild('StorageTests');

/// Adds a tear down to remove the object at [path].
void addTearDownPath(StoragePath path) {
void addTearDownPath(StoragePath path, {StorageBucket? bucket}) {
addTearDown(
() {
try {
return Amplify.Storage.remove(path: path).result;
return Amplify.Storage.remove(
path: path,
options: StorageRemoveOptions(bucket: bucket),
).result;
} on Exception catch (e) {
_logger.warn('Failed to remove file after test', e);
rethrow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ void main() {
() async {
const defaultOptions = StorageDownloadDataOptions(
pluginOptions: S3DownloadDataPluginOptions(),
bucket: StorageBucket.fromBucketInfo(
BucketInfo(bucketName: 'unit-test-bucket', region: 'us-east-2'),
),
);

when(
Expand All @@ -432,6 +435,7 @@ void main() {

downloadDataOperation = storageS3Plugin.downloadData(
path: const StoragePath.fromString('public/$testKey'),
options: defaultOptions,
);

final capturedOptions = verify(
Expand Down Expand Up @@ -766,6 +770,9 @@ void main() {
() async {
const defaultOptions = StorageUploadFileOptions(
pluginOptions: S3UploadFilePluginOptions(),
bucket: StorageBucket.fromBucketInfo(
BucketInfo(bucketName: 'unit-test-bucket', region: 'us-east-2'),
),
);

when(
Expand All @@ -784,6 +791,7 @@ void main() {
uploadFileOperation = storageS3Plugin.uploadFile(
path: testPath,
localFile: testLocalFile,
options: defaultOptions,
);

final capturedParams = verify(
Expand Down Expand Up @@ -1009,6 +1017,9 @@ void main() {
() async {
const defaultOptions = StorageRemoveOptions(
pluginOptions: S3RemovePluginOptions(),
bucket: StorageBucket.fromBucketInfo(
BucketInfo(bucketName: 'unit-test-bucket', region: 'us-east-2'),
),
);
when(
() => storageS3Service.remove(
Expand All @@ -1017,7 +1028,10 @@ void main() {
),
).thenAnswer((_) async => testResult);

final removeOperation = storageS3Plugin.remove(path: testPath);
final removeOperation = storageS3Plugin.remove(
path: testPath,
options: defaultOptions,
);

final capturedOptions = verify(
() => storageS3Service.remove(
Expand Down

0 comments on commit 530140a

Please sign in to comment.