-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(storage): updating mockito suites for delim changes
- Loading branch information
1 parent
7a13ca0
commit d0ce057
Showing
4 changed files
with
198 additions
and
106 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
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
169 changes: 169 additions & 0 deletions
169
packages/storage/amplify_storage_s3_dart/test/amplify_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,169 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'package:amplify_core/amplify_core.dart'; | ||
import 'package:amplify_core/src/types/storage/storage_path_from_identity_id.dart'; | ||
import 'package:amplify_storage_s3_dart/amplify_storage_s3_dart.dart'; | ||
import 'package:amplify_storage_s3_dart/src/model/s3_subpath_strategy.dart'; | ||
import 'package:amplify_storage_s3_dart/src/storage_s3_service/storage_s3_service.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'test_utils/mocks.dart'; | ||
import 'test_utils/test_path_resolver.dart'; | ||
import 'test_utils/test_token_provider.dart'; | ||
|
||
const testPath = StoragePath.fromString('some/path.txt'); | ||
|
||
void main() { | ||
final testConfig = const AmplifyConfig( | ||
storage: StorageConfig( | ||
plugins: { | ||
S3PluginConfig.pluginKey: S3PluginConfig( | ||
bucket: '123', | ||
region: 'west-2', | ||
), | ||
}, | ||
), | ||
// ignore: invalid_use_of_internal_member | ||
).toAmplifyOutputs(); | ||
|
||
final testAuthProviderRepo = AmplifyAuthProviderRepository() | ||
..registerAuthProvider( | ||
APIAuthorizationType.userPools.authProviderToken, | ||
TestTokenIdentityProvider(), | ||
) | ||
..registerAuthProvider( | ||
APIAuthorizationType.iam.authProviderToken, | ||
TestIamAuthProvider(), | ||
); | ||
|
||
group('AmplifyStorageS3Dart API', () { | ||
late DependencyManager dependencyManager; | ||
late AmplifyStorageS3Dart storageS3Plugin; | ||
late StorageS3Service storageS3Service; | ||
|
||
setUp(() async { | ||
dependencyManager = AmplifyDependencyManager(); | ||
storageS3Service = MockStorageS3Service(); | ||
storageS3Plugin = AmplifyStorageS3Dart( | ||
dependencyManagerOverride: dependencyManager, | ||
); | ||
|
||
await storageS3Plugin.configure( | ||
config: testConfig, | ||
authProviderRepo: testAuthProviderRepo, | ||
); | ||
|
||
dependencyManager.addInstance<StorageS3Service>(storageS3Service); | ||
|
||
when( | ||
() => storageS3Service.abortIncompleteMultipartUploads(), | ||
).thenAnswer((_) async {}); | ||
}); | ||
|
||
tearDown(() { | ||
dependencyManager.close(); | ||
}); | ||
|
||
group('list()', () { | ||
const testPath = StoragePath.fromString('some/path'); | ||
final testResult = S3ListResult( | ||
<String>[], | ||
<S3Item>[], | ||
hasNextPage: false, | ||
metadata: S3ListMetadata.fromDelimiter(), | ||
); | ||
|
||
setUpAll(() { | ||
registerFallbackValue( | ||
const StorageListOptions(), | ||
); | ||
}); | ||
|
||
test('should forward default options to StorageS3Service.list() API', | ||
() async { | ||
const defaultOptions = | ||
// StorageListOptions(pluginOptions: S3ListPluginOptions()); | ||
StorageListOptions(subpaths: SubpathStrategy()); | ||
// StorageListOptions(pluginOptions: SubpathStrategy()); | ||
|
||
when( | ||
() => storageS3Service.list( | ||
path: testPath, | ||
options: defaultOptions, | ||
), | ||
).thenAnswer( | ||
(_) async => testResult, | ||
); | ||
|
||
final listOperation = storageS3Plugin.list(path: testPath); | ||
// final listOperation2 = storageS3Plugin.list(path: testPath); | ||
// | ||
final capturedOptions = verify( | ||
() => storageS3Service.list( | ||
path: testPath, | ||
options: captureAny<StorageListOptions>( | ||
named: 'options', | ||
), | ||
), | ||
).captured.last; | ||
|
||
expect( | ||
capturedOptions, | ||
defaultOptions, | ||
); | ||
|
||
final result = await listOperation.result; | ||
expect( | ||
result, | ||
testResult, | ||
); | ||
}); | ||
|
||
// test('should forward options to StorageS3Service.list() API', () async { | ||
// const testOptions = StorageListOptions( | ||
// // pluginOptions: S3ListPluginOptions(), | ||
// subpaths: SubpathStrategy(), | ||
// // pluginOptions: SubpathStrategy.exclude(), | ||
// nextToken: 'next-token-123', | ||
// pageSize: 2, | ||
// ); | ||
// | ||
// when( | ||
// () => storageS3Service.list( | ||
// path: testPath, | ||
// options: testOptions, | ||
// ), | ||
// ).thenAnswer( | ||
// (_) async => testResult, | ||
// ); // returns null if not match | ||
// | ||
// final listOperation = storageS3Plugin.list2( | ||
// path: testPath, | ||
// options: testOptions, | ||
// ); | ||
// | ||
// final capturedOptions = verify( | ||
// () => storageS3Service.list( | ||
// path: testPath, | ||
// options: captureAny<StorageListOptions>( | ||
// named: 'options', | ||
// ), | ||
// ), | ||
// ).captured.last; | ||
// | ||
// expect( | ||
// capturedOptions, | ||
// testOptions, | ||
// ); | ||
// | ||
// final result = await listOperation.result; | ||
// expect( | ||
// result, | ||
// testResult, | ||
// ); | ||
// }); | ||
}); | ||
}); | ||
} |