Skip to content

Commit

Permalink
test(delim): update mockito unit suites for delim changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnandrew committed Jul 9, 2024
1 parent 7a13ca0 commit 95dff17
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
defaultPluginOptions: const SubpathStrategy(),
);
final s3Options = StorageListOptions(
pluginOptions: s3PluginOptions,
subpaths: s3PluginOptions,
nextToken: options?.nextToken,
pageSize: options?.pageSize ?? 1000,
);

return S3ListOperation(
request: StorageListRequest(
path: path,
Expand All @@ -167,17 +166,16 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
nextToken: options?.nextToken,
pageSize: options?.pageSize ?? 1000,
);
final result = storageS3Service.list(
path: path,
options: s3Options,
);

return S3ListOperation(
request: StorageListRequest(
path: path,
options: options,
),
result: result,
result: storageS3Service.list(
path: path,
options: s3Options,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,75 +126,6 @@ class StorageS3Service {
Future<S3ListResult> list({
required StoragePath path,
required StorageListOptions options,
}) async {
final s3PluginOptions = options.pluginOptions as S3ListPluginOptions? ??
const S3ListPluginOptions();

final resolvedPath = await _pathResolver.resolvePath(path: path);

if (!s3PluginOptions.listAll) {
final request = s3.ListObjectsV2Request.build((builder) {
builder
..bucket = _storageOutputs.bucketName
..prefix = resolvedPath
..maxKeys = options.pageSize
..continuationToken = options.nextToken
..delimiter = s3PluginOptions.excludeSubPaths
? s3PluginOptions.delimiter
: null;
});

try {
return S3ListResult.fromPaginatedResult(
await _defaultS3Client.listObjectsV2(request).result,
);
} on smithy.UnknownSmithyHttpException catch (error) {
// S3Client.headObject may return 403 error
throw error.toStorageException();
} on AWSHttpException catch (error) {
throw error.toNetworkException();
}
}

smithy.PaginatedResult<s3.ListObjectsV2Output, int, String> listResult;
S3ListResult recursiveResult;

try {
final request = s3.ListObjectsV2Request.build((builder) {
builder
..bucket = _storageOutputs.bucketName
..prefix = resolvedPath
..delimiter = s3PluginOptions.excludeSubPaths
? s3PluginOptions.delimiter
: null;
});

listResult = await _defaultS3Client.listObjectsV2(request).result;
recursiveResult = S3ListResult.fromPaginatedResult(
listResult,
);

while (listResult.hasNext) {
listResult = await listResult.next().result;
recursiveResult = recursiveResult.merge(
S3ListResult.fromPaginatedResult(
listResult,
),
);
}

return recursiveResult;
} on smithy.UnknownSmithyHttpException catch (error) {
// S3Client.headObject may return 403 error
throw error.toStorageException();
} on AWSHttpException catch (error) {
throw error.toNetworkException();
}
}

Future<S3ListResult> list2({
required StoragePath path,
required StorageListOptions options,
}) async {
final s3PluginOptions =
options.subpaths as SubpathStrategy? ?? const SubpathStrategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ void main() {

test('should forward default options to StorageS3Service.list() API',
() async {
const defaultOptions =
// StorageListOptions(pluginOptions: S3ListPluginOptions());
StorageListOptions(subpaths: SubpathStrategy());
// StorageListOptions(pluginOptions: SubpathStrategy());
const defaultOptions = StorageListOptions(subpaths: SubpathStrategy());

when(
() => storageS3Service.list(
Expand All @@ -115,35 +112,32 @@ void main() {
(_) async => testResult,
);

// final listOperation = storageS3Plugin.list(path: testPath);
// final listOperation = 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,
// );
final listOperation = 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,
);
Expand All @@ -155,9 +149,9 @@ void main() {
),
).thenAnswer(
(_) async => testResult,
); // returns null if not match
);

final listOperation = storageS3Plugin.list2(
final listOperation = storageS3Plugin.list(
path: testPath,
options: testOptions,
);
Expand Down

0 comments on commit 95dff17

Please sign in to comment.