-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-458 Initialize basic storage providers tests with Testcontainers a…
…nd bump dependencies
- Loading branch information
Showing
14 changed files
with
176 additions
and
81 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,21 +1,5 @@ | ||
# | ||
# Copyright (c) 2021 dzikoysk | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License 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. | ||
# | ||
|
||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
20 changes: 20 additions & 0 deletions
20
reposilite-backend/src/main/kotlin/com/reposilite/shared/PicocliExtensions.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,20 @@ | ||
package com.reposilite.shared | ||
|
||
import picocli.CommandLine | ||
|
||
fun <CONFIGURATION : Runnable> loadCommandBasedConfiguration(configuration: CONFIGURATION, description: String): Pair<String, CONFIGURATION> = | ||
description.split(" ", limit = 2) | ||
.let { Pair(it[0], it.getOrNull(1) ?: "") } | ||
.also { | ||
val commandLine = CommandLine(configuration) | ||
|
||
val args = | ||
if (it.second.isEmpty()) | ||
arrayOf() | ||
else | ||
it.second.split(" ").toTypedArray() | ||
|
||
commandLine.execute(*args) | ||
} | ||
.let { Pair(it.first, configuration) } | ||
.also { it.second.run() } |
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
18 changes: 18 additions & 0 deletions
18
reposilite-backend/src/test/kotlin/com/reposilite/storage/FileSystemStorageProviderTest.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,18 @@ | ||
package com.reposilite.storage | ||
|
||
import com.reposilite.storage.infrastructure.FileSystemStorageProviderFactory | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.io.TempDir | ||
import java.io.File | ||
|
||
internal class FileSystemStorageProviderTest : StorageProviderTest() { | ||
|
||
@TempDir | ||
lateinit var rootDirectory: File | ||
|
||
@BeforeEach | ||
fun setup() { | ||
super.storageProvider = FileSystemStorageProviderFactory.of(rootDirectory.toPath(), 1000L) | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
reposilite-backend/src/test/kotlin/com/reposilite/storage/S3StorageProviderTest.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,40 @@ | ||
package com.reposilite.storage | ||
|
||
import com.reposilite.journalist.backend.InMemoryLogger | ||
import com.reposilite.storage.infrastructure.S3StorageProvider | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.testcontainers.containers.localstack.LocalStackContainer | ||
import org.testcontainers.containers.localstack.LocalStackContainer.Service.S3 | ||
import org.testcontainers.junit.jupiter.Container | ||
import org.testcontainers.junit.jupiter.Testcontainers | ||
import org.testcontainers.utility.DockerImageName | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.s3.S3Client | ||
|
||
@Testcontainers | ||
internal class S3StorageProviderTest : StorageProviderTest() { | ||
|
||
@Container | ||
val localstack: LocalStackContainer = LocalStackContainer(DockerImageName.parse("localstack/localstack:0.12.17")) | ||
.withServices(S3) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
val s3 = S3Client.builder() | ||
.endpointOverride(localstack.getEndpointOverride(S3)) | ||
.credentialsProvider( | ||
StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create( | ||
localstack.accessKey, localstack.secretKey | ||
) | ||
) | ||
) | ||
.region(Region.of(localstack.region)) | ||
.build() | ||
|
||
this.storageProvider = S3StorageProvider(InMemoryLogger(), s3, "repositories") | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
reposilite-backend/src/test/kotlin/com/reposilite/storage/StorageProviderTest.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,39 @@ | ||
package com.reposilite.storage | ||
|
||
import com.reposilite.shared.toPath | ||
import org.junit.jupiter.api.Assertions.assertArrayEquals | ||
import org.junit.jupiter.api.Test | ||
import panda.std.ResultAssertions.assertError | ||
import panda.std.ResultAssertions.assertOk | ||
|
||
internal abstract class StorageProviderTest { | ||
|
||
protected lateinit var storageProvider: StorageProvider | ||
|
||
@Test | ||
fun `should store and return valid resource` () { | ||
// given: a destination path to the resource and its content | ||
val path = "/directory/file.data".toPath() | ||
val content = "content".toByteArray() | ||
|
||
// when: non-existing resource is requested | ||
val nonExistingResource = storageProvider.getFile(path) | ||
|
||
// then: response should contain error | ||
assertError(nonExistingResource) | ||
|
||
// when: resource is put in storage and then requested | ||
val putResponse = storageProvider.putFile(path, content) | ||
|
||
// then: put request should succeed | ||
assertOk(putResponse) | ||
|
||
// when: stored resource is requested | ||
val fetchResponse = storageProvider.getFile(path) | ||
|
||
// then: provider should return proper resource | ||
assertOk(fetchResponse) | ||
assertArrayEquals(content, fetchResponse.get().readBytes()) | ||
} | ||
|
||
} |
Oops, something went wrong.