Skip to content

Commit

Permalink
chore(storage): cleanup and enable tests (#4617)
Browse files Browse the repository at this point in the history
* chore: update canary tests

* chore: remove `StorageOperationOptions`

* chore: remove access level from examples

* chore: update doc comment

* chore: enable transfer acceleration tests

* chore: update not found message

* chore: update `S3PathResolver` doc comments

* fix: copy impl

* chore: remove skips from tests

* chore: add back other env to integ tests

* chore: remove targetIdentityId from `S3ListOptions`

* chore: remove try/catch from test

* chore: update formatting

* chore: update copy test
  • Loading branch information
Jordan-Nelson authored Mar 28, 2024
1 parent 36ba0ad commit 0687af6
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 160 deletions.
14 changes: 5 additions & 9 deletions canaries/integration_test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

const data = 'hello, world';
const dataKey = 'hello';
const path = StoragePath.fromString('public/hello');
final event = AnalyticsEvent('hello');

Future<void> performUnauthenticatedActions() async {
// Upload data to Storage
await Amplify.Storage.uploadData(
data: HttpPayload.string(data),
key: dataKey,
path: path,
).result;

// Record Analytics event
Expand All @@ -63,19 +63,15 @@ void main() {
Future<void> performAuthenticatedActions() async {
// Retrieve guest data
final guestData = await Amplify.Storage.downloadData(
key: dataKey,
options: const StorageDownloadDataOptions(
accessLevel: StorageAccessLevel.guest,
),
path: path,
).result;
expect(utf8.decode(guestData.bytes), data);

// Upload data to Storage
await Amplify.Storage.uploadData(
data: HttpPayload.string(data),
key: dataKey,
options: const StorageUploadDataOptions(
accessLevel: StorageAccessLevel.private,
path: StoragePath.withIdentityId(
(String identityId) => 'private/$identityId/hello',
),
).result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
/// {@endtemplate}
///
/// {@template amplify_core.amplify_storage_category.copy_source}
/// The `source` should be readable to the API call originator following
/// corresponding [StorageAccessLevel].
/// The `source` should be readable to the API call originator.
/// {@endtemplate}
StorageCopyOperation copy({
required StoragePath source,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.download_data_options}
/// Configurable options for `Amplify.Storage.downloadData`.
/// {@endtemplate}
class StorageDownloadDataOptions extends StorageOperationOptions
class StorageDownloadDataOptions
with
AWSEquatable<StorageDownloadDataOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.download_file_options}
/// Configurable options for `Amplify.Storage.downloadFile`.
/// {@endtemplate}
class StorageDownloadFileOptions extends StorageOperationOptions
class StorageDownloadFileOptions
with
AWSEquatable<StorageDownloadFileOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.get_properties_options}
/// Configurable options for `Amplify.Storage.getProperties`.
/// {@endtemplate}
class StorageGetPropertiesOptions extends StorageOperationOptions
class StorageGetPropertiesOptions
with
AWSEquatable<StorageGetPropertiesOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.get_url_options}
/// Configurable options for `Amplify.Storage.getUrl`.
/// {@endtemplate}
class StorageGetUrlOptions extends StorageOperationOptions
class StorageGetUrlOptions
with
AWSEquatable<StorageGetUrlOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.list_options}
/// Configurable options for `Amplify.Storage.list`.
/// {@endtemplate}
class StorageListOptions extends StorageOperationOptions
class StorageListOptions
with
AWSEquatable<StorageListOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.remove_many_options}
/// Configurable options for `Amplify.Storage.removeMany`.
/// {@endtemplate}
class StorageRemoveManyOptions extends StorageOperationOptions
class StorageRemoveManyOptions
with
AWSEquatable<StorageRemoveManyOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.remove_options}
/// Configurable options for `Amplify.Storage.remove`.
/// {@endtemplate}
class StorageRemoveOptions extends StorageOperationOptions
class StorageRemoveOptions
with
AWSEquatable<StorageRemoveOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.upload_data_options}
/// Configurable options for `Amplify.Storage.uploadData`.
/// {@endtemplate}
class StorageUploadDataOptions extends StorageOperationOptions
class StorageUploadDataOptions
with
AWSEquatable<StorageUploadDataOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/src/types/storage/base/storage_operation_options.dart';
import 'package:aws_common/aws_common.dart';

/// {@template amplify_core.storage.upload_file_options}
/// Configurable options for `Amplify.Storage.uploadFile`.
/// {@endtemplate}
class StorageUploadFileOptions extends StorageOperationOptions
class StorageUploadFileOptions
with
AWSEquatable<StorageUploadFileOptions>,
AWSSerializable<Map<String, Object?>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import 'package:amplify_core/amplify_core.dart';

class TestTransferAccelerationConfig<T> {
const TestTransferAccelerationConfig({
required this.targetKey,
required this.targetAccessLevel,
required this.targetPath,
required this.uploadSource,
required this.referenceBytes,
});

final String targetKey;
final StorageAccessLevel targetAccessLevel;
final StoragePath targetPath;
final T uploadSource;
final List<int> referenceBytes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void testTransferAcceleration({
tearDownAll(() async {
for (final dataPayload in dataPayloads) {
await Amplify.Storage.remove(
path: StoragePath.fromString(dataPayload.targetKey),
path: dataPayload.targetPath,
).result;
}
});
Expand All @@ -27,9 +27,7 @@ void testTransferAcceleration({
final dataPayload = entry.value;
final operation = Amplify.Storage.uploadData(
data: dataPayload.uploadSource,
path: StoragePath.fromString(
'/${dataPayload.targetAccessLevel}/${dataPayload.targetKey}',
),
path: dataPayload.targetPath,
options: const StorageUploadDataOptions(
pluginOptions:
S3UploadDataPluginOptions(useAccelerateEndpoint: true),
Expand All @@ -49,9 +47,7 @@ void testTransferAcceleration({
test('S3DataPayload ${entry.key}', () async {
final dataPayload = entry.value;
final result = await Amplify.Storage.getUrl(
path: StoragePath.fromString(
'/${dataPayload.targetAccessLevel}/${dataPayload.targetKey}',
),
path: dataPayload.targetPath,
options: const StorageGetUrlOptions(
pluginOptions: S3GetUrlPluginOptions(
expiresIn: Duration(minutes: 5),
Expand All @@ -70,9 +66,7 @@ void testTransferAcceleration({
test('S3DataPayload ${entry.key}', () async {
final dataPayload = entry.value;
final result = await Amplify.Storage.downloadData(
path: StoragePath.fromString(
'/${dataPayload.targetAccessLevel}/${dataPayload.targetKey}',
),
path: dataPayload.targetPath,
options: const StorageDownloadDataOptions(
pluginOptions: S3DownloadDataPluginOptions(
useAccelerateEndpoint: true,
Expand All @@ -92,7 +86,7 @@ void testTransferAcceleration({
tearDownAll(() async {
for (final awsFile in awsFiles) {
await Amplify.Storage.remove(
path: StoragePath.fromString(awsFile.targetKey),
path: awsFile.targetPath,
).result;
}
});
Expand All @@ -103,9 +97,7 @@ void testTransferAcceleration({
final awsFile = entry.value;
final operation = Amplify.Storage.uploadFile(
localFile: awsFile.uploadSource,
path: StoragePath.fromString(
'${awsFile.targetAccessLevel}/${awsFile.targetKey}',
),
path: awsFile.targetPath,
options: const StorageUploadFileOptions(
pluginOptions: S3UploadFilePluginOptions(
useAccelerateEndpoint: true,
Expand All @@ -128,9 +120,7 @@ void testTransferAcceleration({
() async {
final awsFile = entry.value;
final result = await Amplify.Storage.getUrl(
path: StoragePath.fromString(
'${awsFile.targetAccessLevel}/${awsFile.targetKey}',
),
path: awsFile.targetPath,
options: const StorageGetUrlOptions(
pluginOptions: S3GetUrlPluginOptions(
expiresIn: Duration(minutes: 5),
Expand All @@ -154,9 +144,7 @@ void testTransferAcceleration({
const end = 5 * 1024 + 12;
final awsFile = entry.value;
final result = await Amplify.Storage.downloadData(
path: StoragePath.fromString(
'${awsFile.targetAccessLevel}/${awsFile.targetKey}',
),
path: awsFile.targetPath,
options: StorageDownloadDataOptions(
pluginOptions: S3DownloadDataPluginOptions(
useAccelerateEndpoint: true,
Expand Down
Loading

0 comments on commit 0687af6

Please sign in to comment.