Skip to content

Commit 95dff17

Browse files
committed
test(delim): update mockito unit suites for delim changes
1 parent 7a13ca0 commit 95dff17

File tree

3 files changed

+29
-106
lines changed

3 files changed

+29
-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
);

0 commit comments

Comments
 (0)