-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): update uploadData API to accept optional storage bucke…
…t param (#5540)
- Loading branch information
Showing
19 changed files
with
466 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
packages/amplify_core/lib/src/types/storage/bucket_info.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import 'package:amplify_core/amplify_core.dart'; | ||
|
||
/// {@template amplify_core.storage.bucket_info} | ||
/// Presents a storage bucket information. | ||
/// {@endtemplate} | ||
class BucketInfo { | ||
class BucketInfo with AWSEquatable<BucketInfo> { | ||
/// {@macro amplify_core.storage.bucket_info} | ||
const BucketInfo({required this.bucketName, required this.region}); | ||
final String bucketName; | ||
final String region; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
bucketName, | ||
region, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/amplify_core/test/types/storage/storage_bucket_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'package:amplify_core/amplify_core.dart'; | ||
import 'package:amplify_core/src/config/amplify_outputs/storage/bucket_outputs.dart'; | ||
import 'package:amplify_core/src/config/amplify_outputs/storage/storage_outputs.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Storage bucket resolve BucketInfo', () { | ||
const defaultBucketOutputs = BucketOutputs( | ||
name: 'default-bucket-friendly-name', | ||
bucketName: 'default-bucket-unique-name', | ||
awsRegion: 'default-bucket-aws-region', | ||
); | ||
const secondBucketOutputs = BucketOutputs( | ||
name: 'second-bucket-friendly-name', | ||
bucketName: 'second-bucket-unique-name', | ||
awsRegion: 'second-bucket-aws-region', | ||
); | ||
final defaultBucketInfo = BucketInfo( | ||
bucketName: defaultBucketOutputs.bucketName, | ||
region: defaultBucketOutputs.awsRegion, | ||
); | ||
final secondBucketInfo = BucketInfo( | ||
bucketName: secondBucketOutputs.bucketName, | ||
region: secondBucketOutputs.awsRegion, | ||
); | ||
final testStorageOutputsMultiBucket = StorageOutputs( | ||
awsRegion: defaultBucketOutputs.awsRegion, | ||
bucketName: defaultBucketOutputs.bucketName, | ||
buckets: [ | ||
defaultBucketOutputs, | ||
secondBucketOutputs, | ||
], | ||
); | ||
final testStorageOutputsSingleBucket = StorageOutputs( | ||
awsRegion: defaultBucketOutputs.awsRegion, | ||
bucketName: defaultBucketOutputs.bucketName, | ||
); | ||
|
||
test( | ||
'should return same bucket info when storage bucket is created from' | ||
' a bucket info', () { | ||
final storageBucket = StorageBucket.fromBucketInfo( | ||
defaultBucketInfo, | ||
); | ||
final bucketInfo = storageBucket.resolveBucketInfo(null); | ||
expect(bucketInfo, defaultBucketInfo); | ||
}); | ||
|
||
test( | ||
'should return bucket info when storage bucket is created from' | ||
' buckets in storage outputs', () { | ||
final storageBucket = StorageBucket.fromOutputs(secondBucketOutputs.name); | ||
final bucketInfo = | ||
storageBucket.resolveBucketInfo(testStorageOutputsMultiBucket); | ||
expect(bucketInfo, secondBucketInfo); | ||
}); | ||
|
||
test( | ||
'should throw assertion error when storage bucket is created from' | ||
' outputs and storage outputs is null', () { | ||
final storageBucket = | ||
StorageBucket.fromOutputs(defaultBucketOutputs.name); | ||
expect( | ||
() => storageBucket.resolveBucketInfo(null), | ||
throwsA(isA<AssertionError>()), | ||
); | ||
}); | ||
test( | ||
'should throw exception when storage bucket is created from outputs and' | ||
' storage outputs does not have buckets', () { | ||
final storageBucket = StorageBucket.fromOutputs('bucket-name'); | ||
expect( | ||
() => storageBucket.resolveBucketInfo(testStorageOutputsSingleBucket), | ||
throwsA(isA<InvalidStorageBucketException>()), | ||
); | ||
}); | ||
test( | ||
'should throw exception when storage bucket is created from outputs and' | ||
' bucket name does not match any bucket in storage outputs', () { | ||
final storageBucket = StorageBucket.fromOutputs('invalid-bucket-name'); | ||
expect( | ||
() => storageBucket.resolveBucketInfo(testStorageOutputsMultiBucket), | ||
throwsA(isA<InvalidStorageBucketException>()), | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.