Skip to content

Commit

Permalink
removed the use of specific s3 bucket names and regions, moved testin…
Browse files Browse the repository at this point in the history
…g for StorageNotFoundException into its own test that made more sense
  • Loading branch information
ekjotmultani committed Oct 21, 2024
1 parent 3d717dd commit 3a13b3d
Showing 1 changed file with 18 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,32 @@ void main() {
});
});
group('multibucket config', () {
final mainBucket =
StorageBucket.fromOutputs('Storage Integ Test main bucket');
final secondaryBucket =
StorageBucket.fromOutputs('Storage Integ Test secondary bucket');
setUpAll(() async {
await configure(amplifyEnvironments['main']!);
addTearDownPath(StoragePath.fromString(path));
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(data),
path: StoragePath.fromString(path),
options: const StorageUploadDataOptions(metadata: metadata),
bucket: const StorageBucket.fromBucketInfo(
BucketInfo(
bucketName:
'amplify-main-main-sandbox-storageintegtestsecondar-mxf6yc4ivr2h',
region: 'us-west-2',
),
),
bucket: mainBucket,
).result;
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(data),
path: StoragePath.fromString(path),
options: const StorageUploadDataOptions(metadata: metadata),
bucket: StorageBucket.fromOutputs('Storage Integ Test main bucket'),
bucket: secondaryBucket,
).result;
});

testWidgets('String StoragePath', (_) async {
final result = await Amplify.Storage.getProperties(
path: StoragePath.fromString(path),
options: const StorageGetPropertiesOptions(
bucket: StorageBucket.fromBucketInfo(
BucketInfo(
bucketName:
'amplify-main-main-sandbox-storageintegtestmainbuck-nmfvvkcjjel6',
region: 'us-west-2',
),
),
options: StorageGetPropertiesOptions(
bucket: mainBucket,
),
).result;
expect(result.storageItem.path, path);
Expand All @@ -146,9 +138,7 @@ void main() {
final resultSecondaryBucket = await Amplify.Storage.getProperties(
path: StoragePath.fromString(path),
options: StorageGetPropertiesOptions(
bucket: StorageBucket.fromOutputs(
'Storage Integ Test secondary bucket',
),
bucket: secondaryBucket,
),
).result;
expect(resultSecondaryBucket.storageItem.path, path);
Expand All @@ -158,10 +148,6 @@ void main() {
});

testWidgets('with identity ID', (_) async {
final mainBucket =
StorageBucket.fromOutputs('Storage Integ Test main bucket');
final secondaryBucket =
StorageBucket.fromOutputs('Storage Integ Test secondary bucket');
final userIdentityId = await signInNewUser();
final name = 'get-properties-with-identity-id-${uuid()}';
final data = 'with identity ID'.codeUnits;
Expand All @@ -185,33 +171,25 @@ void main() {
expect(result.storageItem.metadata, metadata);
expect(result.storageItem.eTag, isNotNull);
expect(result.storageItem.size, data.length);
});

testWidgets('not existent path', (_) async {
// we expect StorageNotFoundException here since there is no data uploaded to either bucket on this path
await expectLater(
Amplify.Storage.getProperties(
path: StoragePath.fromIdentityId(
((identityId) => 'private/$identityId/$name'),
),
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('public/not-existent-path'),
options: StorageGetPropertiesOptions(
bucket: mainBucket,
),
).result,
throwsA(isA<StorageNotFoundException>()),
);
// we expect this error here since the main bucket does not have this data uploaded
});

testWidgets('unauthorized path', (_) async {
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('unauthorized/path'),
).result,
throwsA(isA<StorageAccessDeniedException>()),
);
});

testWidgets('not existent path', (_) async {
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('public/not-existent-path'),
options: StorageGetPropertiesOptions(
bucket: secondaryBucket,
),
).result,
throwsA(isA<StorageNotFoundException>()),
);
Expand Down

0 comments on commit 3a13b3d

Please sign in to comment.