-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): add delimiter support (#2871)
- Loading branch information
1 parent
45a2451
commit cf64793
Showing
18 changed files
with
684 additions
and
29 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
201 changes: 201 additions & 0 deletions
201
...c/androidTest/java/com/amplifyframework/storage/s3/AWSS3StorageSubPathStrategyListTest.kt
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,201 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.storage.s3 | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin | ||
import com.amplifyframework.storage.StorageCategory | ||
import com.amplifyframework.storage.StoragePath | ||
import com.amplifyframework.storage.options.StorageRemoveOptions | ||
import com.amplifyframework.storage.options.StorageUploadFileOptions | ||
import com.amplifyframework.storage.options.SubpathStrategy | ||
import com.amplifyframework.storage.s3.options.AWSS3StoragePagedListOptions | ||
import com.amplifyframework.storage.s3.test.R | ||
import com.amplifyframework.storage.s3.util.WorkmanagerTestUtils | ||
import com.amplifyframework.testutils.random.RandomTempFile | ||
import com.amplifyframework.testutils.sync.SynchronousAuth | ||
import com.amplifyframework.testutils.sync.SynchronousStorage | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.ints.shouldBeExactly | ||
import io.kotest.matchers.nulls.shouldBeNull | ||
import java.io.File | ||
import org.junit.After | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
/** | ||
* Integration tests for using SubpathStrategy with Storage List API | ||
*/ | ||
class AWSS3StorageSubPathStrategyListTest { | ||
companion object { | ||
private const val SMALL_FILE_SIZE = 100L | ||
private const val FIRST_FILE_NAME = "01" | ||
private const val SECOND_FILE_NAME = "02" | ||
private const val THIRD_FILE_NAME = "03" | ||
private const val FOURTH_FILE_NAME = "04" | ||
private const val FIFTH_FILE_NAME = "05" | ||
private const val CUSTOM_FILE_NAME = "custom" | ||
private const val FIRST_FILE_STRING_PATH = "public/photos/2023/$FIRST_FILE_NAME" | ||
private val FIRST_FILE_PATH = StoragePath.fromString(FIRST_FILE_STRING_PATH) | ||
private const val SECOND_FILE_STRING_PATH = "public/photos/2023/$SECOND_FILE_NAME" | ||
private val SECOND_FILE_PATH = StoragePath.fromString(SECOND_FILE_STRING_PATH) | ||
private const val THIRD_FILE_STRING_PATH = "public/photos/2024/$THIRD_FILE_NAME" | ||
private val THIRD_FILE_PATH = StoragePath.fromString(THIRD_FILE_STRING_PATH) | ||
private const val FOURTH_FILE_STRING_PATH = "public/photos/2024/$FOURTH_FILE_NAME" | ||
private val FOURTH_FILE_PATH = StoragePath.fromString(FOURTH_FILE_STRING_PATH) | ||
private const val FIFTH_FILE_STRING_PATH = "public/photos/$FIFTH_FILE_NAME" | ||
private val FIFTH_FILE_PATH = StoragePath.fromString(FIFTH_FILE_STRING_PATH) | ||
private const val CUSTOM_FILE_STRING_PATH = "public/photos/202$/$CUSTOM_FILE_NAME" | ||
private val CUSTOM_FILE_PATH = StoragePath.fromString(CUSTOM_FILE_STRING_PATH) | ||
|
||
lateinit var storageCategory: StorageCategory | ||
lateinit var synchronousStorage: SynchronousStorage | ||
lateinit var synchronousAuth: SynchronousAuth | ||
private lateinit var first: File | ||
private lateinit var second: File | ||
private lateinit var third: File | ||
private lateinit var fourth: File | ||
private lateinit var fifth: File | ||
private lateinit var customFile: File | ||
|
||
/** | ||
* Initialize mobile client and configure the storage. | ||
* Upload the test files ahead of time. | ||
*/ | ||
@JvmStatic | ||
@BeforeClass | ||
fun setUpOnce() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
WorkmanagerTestUtils.initializeWorkmanagerTestUtil(context) | ||
|
||
synchronousAuth = SynchronousAuth.delegatingToCognito(context, AWSCognitoAuthPlugin()) | ||
|
||
// Get a handle to storage | ||
storageCategory = TestStorageCategory.create(context, R.raw.amplifyconfiguration) | ||
synchronousStorage = SynchronousStorage.delegatingTo(storageCategory) | ||
|
||
// Upload test files | ||
first = RandomTempFile(FIRST_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(FIRST_FILE_PATH, first, StorageUploadFileOptions.defaultInstance()) | ||
second = RandomTempFile(SECOND_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(SECOND_FILE_PATH, second, StorageUploadFileOptions.defaultInstance()) | ||
third = RandomTempFile(THIRD_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(THIRD_FILE_PATH, third, StorageUploadFileOptions.defaultInstance()) | ||
fourth = RandomTempFile(FOURTH_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(FOURTH_FILE_PATH, fourth, StorageUploadFileOptions.defaultInstance()) | ||
fifth = RandomTempFile(FIFTH_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(FIFTH_FILE_PATH, fifth, StorageUploadFileOptions.defaultInstance()) | ||
|
||
customFile = RandomTempFile(CUSTOM_FILE_NAME, SMALL_FILE_SIZE) | ||
synchronousStorage.uploadFile(CUSTOM_FILE_PATH, customFile, StorageUploadFileOptions.defaultInstance()) | ||
} | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
synchronousStorage.remove("photos/2023/$FIRST_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
synchronousStorage.remove("photos/2023/$SECOND_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
synchronousStorage.remove("photos/2024/$THIRD_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
synchronousStorage.remove("photos/2024/$FOURTH_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
synchronousStorage.remove("photos/$FIFTH_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
synchronousStorage.remove("photos/$CUSTOM_FILE_NAME", StorageRemoveOptions.defaultInstance()) | ||
} | ||
|
||
@Test | ||
fun testListWithIncludeStrategyAndStoragePath() { | ||
val path = StoragePath.fromString("public/photos/") | ||
val options = AWSS3StoragePagedListOptions | ||
.builder() | ||
.setPageSize(10) | ||
.setSubpathStrategy(SubpathStrategy.Include) | ||
.build() | ||
|
||
val result = synchronousStorage.list(path, options) | ||
|
||
result.items.size shouldBeExactly(6) | ||
result.items.mapNotNull { it.path } shouldContainExactly listOf( | ||
"public/photos/05", | ||
"public/photos/202$/custom", | ||
"public/photos/2023/01", | ||
"public/photos/2023/02", | ||
"public/photos/2024/03", | ||
"public/photos/2024/04" | ||
) | ||
} | ||
|
||
@Test | ||
fun testListWithExcludeStrategyAndStoragePath() { | ||
val options = AWSS3StoragePagedListOptions | ||
.builder() | ||
.setPageSize(10) | ||
.setSubpathStrategy(SubpathStrategy.Exclude()) | ||
.build() | ||
|
||
var result = synchronousStorage.list(StoragePath.fromString("public/photos/"), options) | ||
|
||
result.items.size shouldBeExactly(1) | ||
result.items.mapNotNull { it.path } shouldContainExactly listOf("public/photos/05") | ||
|
||
result.excludedSubpaths.size shouldBeExactly(3) | ||
result.excludedSubpaths shouldContainExactly listOf( | ||
"public/photos/202$/", | ||
"public/photos/2023/", | ||
"public/photos/2024/" | ||
) | ||
|
||
result = synchronousStorage.list(StoragePath.fromString("public/photos/2023/"), options) | ||
|
||
result.items.size shouldBeExactly(2) | ||
result.items.mapNotNull { it.path } shouldContainExactly listOf( | ||
"public/photos/2023/01", | ||
"public/photos/2023/02" | ||
) | ||
|
||
result.excludedSubpaths.shouldBeNull() | ||
} | ||
|
||
@Test | ||
fun testListWithExcludeCustomDelimiterStrategyAndStoragePath() { | ||
val options = AWSS3StoragePagedListOptions | ||
.builder() | ||
.setPageSize(10) | ||
.setSubpathStrategy(SubpathStrategy.Exclude("$")) | ||
.build() | ||
|
||
var result = synchronousStorage.list(StoragePath.fromString("public/photos/"), options) | ||
|
||
result.items.size shouldBeExactly(5) | ||
result.items.mapNotNull { it.path } shouldContainExactly listOf( | ||
"public/photos/05", | ||
"public/photos/2023/01", | ||
"public/photos/2023/02", | ||
"public/photos/2024/03", | ||
"public/photos/2024/04" | ||
) | ||
|
||
result.excludedSubpaths.size shouldBeExactly(1) | ||
result.excludedSubpaths shouldContainExactly listOf("public/photos/202$") | ||
|
||
result = synchronousStorage.list(StoragePath.fromString("public/photos/2023/"), options) | ||
|
||
result.items.size shouldBeExactly(2) | ||
result.items.mapNotNull { it.path } shouldContainExactly listOf( | ||
"public/photos/2023/01", | ||
"public/photos/2023/02", | ||
) | ||
} | ||
} |
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
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
Oops, something went wrong.