Skip to content

Commit d0ce057

Browse files
committed
test(storage): updating mockito suites for delim changes
1 parent 7a13ca0 commit d0ce057

File tree

4 files changed

+198
-106
lines changed

4 files changed

+198
-106
lines changed

packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,10 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
136136
defaultPluginOptions: const SubpathStrategy(),
137137
);
138138
final s3Options = StorageListOptions(
139-
pluginOptions: s3PluginOptions,
139+
subpaths: s3PluginOptions,
140140
nextToken: options?.nextToken,
141141
pageSize: options?.pageSize ?? 1000,
142142
);
143-
144143
return S3ListOperation(
145144
request: StorageListRequest(
146145
path: path,
@@ -167,17 +166,16 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
167166
nextToken: options?.nextToken,
168167
pageSize: options?.pageSize ?? 1000,
169168
);
170-
final result = storageS3Service.list(
171-
path: path,
172-
options: s3Options,
173-
);
174169

175170
return S3ListOperation(
176171
request: StorageListRequest(
177172
path: path,
178173
options: options,
179174
),
180-
result: result,
175+
result: storageS3Service.list(
176+
path: path,
177+
options: s3Options,
178+
),
181179
);
182180
}
183181

packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -126,75 +126,6 @@ class StorageS3Service {
126126
Future<S3ListResult> list({
127127
required StoragePath path,
128128
required StorageListOptions options,
129-
}) async {
130-
final s3PluginOptions = options.pluginOptions as S3ListPluginOptions? ??
131-
const S3ListPluginOptions();
132-
133-
final resolvedPath = await _pathResolver.resolvePath(path: path);
134-
135-
if (!s3PluginOptions.listAll) {
136-
final request = s3.ListObjectsV2Request.build((builder) {
137-
builder
138-
..bucket = _storageOutputs.bucketName
139-
..prefix = resolvedPath
140-
..maxKeys = options.pageSize
141-
..continuationToken = options.nextToken
142-
..delimiter = s3PluginOptions.excludeSubPaths
143-
? s3PluginOptions.delimiter
144-
: null;
145-
});
146-
147-
try {
148-
return S3ListResult.fromPaginatedResult(
149-
await _defaultS3Client.listObjectsV2(request).result,
150-
);
151-
} on smithy.UnknownSmithyHttpException catch (error) {
152-
// S3Client.headObject may return 403 error
153-
throw error.toStorageException();
154-
} on AWSHttpException catch (error) {
155-
throw error.toNetworkException();
156-
}
157-
}
158-
159-
smithy.PaginatedResult<s3.ListObjectsV2Output, int, String> listResult;
160-
S3ListResult recursiveResult;
161-
162-
try {
163-
final request = s3.ListObjectsV2Request.build((builder) {
164-
builder
165-
..bucket = _storageOutputs.bucketName
166-
..prefix = resolvedPath
167-
..delimiter = s3PluginOptions.excludeSubPaths
168-
? s3PluginOptions.delimiter
169-
: null;
170-
});
171-
172-
listResult = await _defaultS3Client.listObjectsV2(request).result;
173-
recursiveResult = S3ListResult.fromPaginatedResult(
174-
listResult,
175-
);
176-
177-
while (listResult.hasNext) {
178-
listResult = await listResult.next().result;
179-
recursiveResult = recursiveResult.merge(
180-
S3ListResult.fromPaginatedResult(
181-
listResult,
182-
),
183-
);
184-
}
185-
186-
return recursiveResult;
187-
} on smithy.UnknownSmithyHttpException catch (error) {
188-
// S3Client.headObject may return 403 error
189-
throw error.toStorageException();
190-
} on AWSHttpException catch (error) {
191-
throw error.toNetworkException();
192-
}
193-
}
194-
195-
Future<S3ListResult> list2({
196-
required StoragePath path,
197-
required StorageListOptions options,
198129
}) async {
199130
final s3PluginOptions =
200131
options.subpaths as SubpathStrategy? ?? const SubpathStrategy();

packages/storage/amplify_storage_s3_dart/test/amplify_storage_s3_dart_test.dart

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ void main() {
101101

102102
test('should forward default options to StorageS3Service.list() API',
103103
() async {
104-
const defaultOptions =
105-
// StorageListOptions(pluginOptions: S3ListPluginOptions());
106-
StorageListOptions(subpaths: SubpathStrategy());
107-
// StorageListOptions(pluginOptions: SubpathStrategy());
104+
const defaultOptions = StorageListOptions(subpaths: SubpathStrategy());
108105

109106
when(
110107
() => storageS3Service.list(
@@ -115,35 +112,32 @@ void main() {
115112
(_) async => testResult,
116113
);
117114

118-
// final listOperation = storageS3Plugin.list(path: testPath);
119-
// final listOperation = storageS3Plugin.list(path: testPath);
120-
121-
// final capturedOptions = verify(
122-
// () => storageS3Service.list(
123-
// path: testPath,
124-
// options: captureAny<StorageListOptions>(
125-
// named: 'options',
126-
// ),
127-
// ),
128-
// ).captured.last;
129-
//
130-
// expect(
131-
// capturedOptions,
132-
// defaultOptions,
133-
// );
134-
//
135-
// final result = await listOperation.result;
136-
// expect(
137-
// result,
138-
// testResult,
139-
// );
115+
final listOperation = storageS3Plugin.list(path: testPath);
116+
117+
final capturedOptions = verify(
118+
() => storageS3Service.list(
119+
path: testPath,
120+
options: captureAny<StorageListOptions>(
121+
named: 'options',
122+
),
123+
),
124+
).captured.last;
125+
126+
expect(
127+
capturedOptions,
128+
defaultOptions,
129+
);
130+
131+
final result = await listOperation.result;
132+
expect(
133+
result,
134+
testResult,
135+
);
140136
});
141137

142138
test('should forward options to StorageS3Service.list() API', () async {
143139
const testOptions = StorageListOptions(
144-
// pluginOptions: S3ListPluginOptions(),
145140
subpaths: SubpathStrategy(),
146-
// pluginOptions: SubpathStrategy.exclude(),
147141
nextToken: 'next-token-123',
148142
pageSize: 2,
149143
);
@@ -155,9 +149,9 @@ void main() {
155149
),
156150
).thenAnswer(
157151
(_) async => testResult,
158-
); // returns null if not match
152+
);
159153

160-
final listOperation = storageS3Plugin.list2(
154+
final listOperation = storageS3Plugin.list(
161155
path: testPath,
162156
options: testOptions,
163157
);
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import 'package:amplify_core/amplify_core.dart';
5+
import 'package:amplify_core/src/types/storage/storage_path_from_identity_id.dart';
6+
import 'package:amplify_storage_s3_dart/amplify_storage_s3_dart.dart';
7+
import 'package:amplify_storage_s3_dart/src/model/s3_subpath_strategy.dart';
8+
import 'package:amplify_storage_s3_dart/src/storage_s3_service/storage_s3_service.dart';
9+
import 'package:mocktail/mocktail.dart';
10+
import 'package:test/test.dart';
11+
12+
import 'test_utils/mocks.dart';
13+
import 'test_utils/test_path_resolver.dart';
14+
import 'test_utils/test_token_provider.dart';
15+
16+
const testPath = StoragePath.fromString('some/path.txt');
17+
18+
void main() {
19+
final testConfig = const AmplifyConfig(
20+
storage: StorageConfig(
21+
plugins: {
22+
S3PluginConfig.pluginKey: S3PluginConfig(
23+
bucket: '123',
24+
region: 'west-2',
25+
),
26+
},
27+
),
28+
// ignore: invalid_use_of_internal_member
29+
).toAmplifyOutputs();
30+
31+
final testAuthProviderRepo = AmplifyAuthProviderRepository()
32+
..registerAuthProvider(
33+
APIAuthorizationType.userPools.authProviderToken,
34+
TestTokenIdentityProvider(),
35+
)
36+
..registerAuthProvider(
37+
APIAuthorizationType.iam.authProviderToken,
38+
TestIamAuthProvider(),
39+
);
40+
41+
group('AmplifyStorageS3Dart API', () {
42+
late DependencyManager dependencyManager;
43+
late AmplifyStorageS3Dart storageS3Plugin;
44+
late StorageS3Service storageS3Service;
45+
46+
setUp(() async {
47+
dependencyManager = AmplifyDependencyManager();
48+
storageS3Service = MockStorageS3Service();
49+
storageS3Plugin = AmplifyStorageS3Dart(
50+
dependencyManagerOverride: dependencyManager,
51+
);
52+
53+
await storageS3Plugin.configure(
54+
config: testConfig,
55+
authProviderRepo: testAuthProviderRepo,
56+
);
57+
58+
dependencyManager.addInstance<StorageS3Service>(storageS3Service);
59+
60+
when(
61+
() => storageS3Service.abortIncompleteMultipartUploads(),
62+
).thenAnswer((_) async {});
63+
});
64+
65+
tearDown(() {
66+
dependencyManager.close();
67+
});
68+
69+
group('list()', () {
70+
const testPath = StoragePath.fromString('some/path');
71+
final testResult = S3ListResult(
72+
<String>[],
73+
<S3Item>[],
74+
hasNextPage: false,
75+
metadata: S3ListMetadata.fromDelimiter(),
76+
);
77+
78+
setUpAll(() {
79+
registerFallbackValue(
80+
const StorageListOptions(),
81+
);
82+
});
83+
84+
test('should forward default options to StorageS3Service.list() API',
85+
() async {
86+
const defaultOptions =
87+
// StorageListOptions(pluginOptions: S3ListPluginOptions());
88+
StorageListOptions(subpaths: SubpathStrategy());
89+
// StorageListOptions(pluginOptions: SubpathStrategy());
90+
91+
when(
92+
() => storageS3Service.list(
93+
path: testPath,
94+
options: defaultOptions,
95+
),
96+
).thenAnswer(
97+
(_) async => testResult,
98+
);
99+
100+
final listOperation = storageS3Plugin.list(path: testPath);
101+
// final listOperation2 = storageS3Plugin.list(path: testPath);
102+
//
103+
final capturedOptions = verify(
104+
() => storageS3Service.list(
105+
path: testPath,
106+
options: captureAny<StorageListOptions>(
107+
named: 'options',
108+
),
109+
),
110+
).captured.last;
111+
112+
expect(
113+
capturedOptions,
114+
defaultOptions,
115+
);
116+
117+
final result = await listOperation.result;
118+
expect(
119+
result,
120+
testResult,
121+
);
122+
});
123+
124+
// test('should forward options to StorageS3Service.list() API', () async {
125+
// const testOptions = StorageListOptions(
126+
// // pluginOptions: S3ListPluginOptions(),
127+
// subpaths: SubpathStrategy(),
128+
// // pluginOptions: SubpathStrategy.exclude(),
129+
// nextToken: 'next-token-123',
130+
// pageSize: 2,
131+
// );
132+
//
133+
// when(
134+
// () => storageS3Service.list(
135+
// path: testPath,
136+
// options: testOptions,
137+
// ),
138+
// ).thenAnswer(
139+
// (_) async => testResult,
140+
// ); // returns null if not match
141+
//
142+
// final listOperation = storageS3Plugin.list2(
143+
// path: testPath,
144+
// options: testOptions,
145+
// );
146+
//
147+
// final capturedOptions = verify(
148+
// () => storageS3Service.list(
149+
// path: testPath,
150+
// options: captureAny<StorageListOptions>(
151+
// named: 'options',
152+
// ),
153+
// ),
154+
// ).captured.last;
155+
//
156+
// expect(
157+
// capturedOptions,
158+
// testOptions,
159+
// );
160+
//
161+
// final result = await listOperation.result;
162+
// expect(
163+
// result,
164+
// testResult,
165+
// );
166+
// });
167+
});
168+
});
169+
}

0 commit comments

Comments
 (0)