Skip to content

Commit

Permalink
chore(storage): storage copy integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyllark committed Nov 14, 2024
1 parent a4d16d7 commit ca5e567
Showing 1 changed file with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,89 @@ void main() {
expect(result.copiedItem.path, destinationPath);
});
});

group('multi bucket', () {
final bucketData = 'copy data'.codeUnits;
final bucket1 = StorageBucket.fromOutputs(
'Storage Integ Test main bucket',
);
final bucket2 = StorageBucket.fromOutputs(
'Storage Integ Test secondary bucket',
);
final bucket1PathSource = 'public/multi-bucket-get-url-${uuid()}';
final bucket2PathSource = 'public/multi-bucket-get-url-${uuid()}';
final bucket2PathDestination = 'public/multi-bucket-get-url-${uuid()}';
final storageBucket1PathSource =
StoragePath.fromString(bucket1PathSource);
final storageBucket2PathSource =
StoragePath.fromString(bucket2PathSource);
final storageBucket2PathDestination =
StoragePath.fromString(bucket2PathDestination);

setUp(() async {
addTearDownPath(storageBucket1PathSource);
addTearDownPath(storageBucket2PathSource);
addTearDownPath(storageBucket2PathDestination);
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(bucketData),
path: storageBucket1PathSource,
options: StorageUploadDataOptions(
bucket: bucket1,
),
).result;
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(bucketData),
path: storageBucket2PathSource,
options: StorageUploadDataOptions(
bucket: bucket2,
),
).result;
});

testWidgets('copy to a different bucket', (_) async {
final result = Amplify.Storage.copy(
source: storageBucket1PathSource,
destination: storageBucket2PathDestination,
options: StorageCopyOptions(
buckets: CopyBuckets(
source: bucket1,
destination: bucket2,
),
),
).result;
expect(await result, returnsNormally);

final downloadResult = await Amplify.Storage.downloadData(
path: storageBucket2PathDestination,
options: StorageDownloadDataOptions(bucket: bucket2),
).result;
expect(
downloadResult.bytes,
bucketData,
);
});

testWidgets('copy to the same bucket', (_) async {
final result = Amplify.Storage.copy(
source: storageBucket2PathSource,
destination: storageBucket2PathDestination,
options: StorageCopyOptions(
buckets: CopyBuckets.sameBucket(
bucket2,
),
),
).result;
expect(await result, returnsNormally);

final downloadResult = await Amplify.Storage.downloadData(
path: storageBucket2PathDestination,
options: StorageDownloadDataOptions(bucket: bucket2),
).result;
expect(
downloadResult.bytes,
bucketData,
);
});
});
});
}

0 comments on commit ca5e567

Please sign in to comment.