Skip to content

Commit 6e955b5

Browse files
committed
Fix tests
- Add default spring configuration for integration tests - Add S3 configuration in ControllerTestBase - Change coroutines management in Workspace module
1 parent b55d0a9 commit 6e955b5

File tree

16 files changed

+172
-54
lines changed

16 files changed

+172
-54
lines changed

api/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ plugins {
1111
id("org.jetbrains.kotlinx.kover")
1212
}
1313

14-
val testNgVersion = "7.8.0"
15-
val testContainersRedisVersion = "1.6.4"
16-
val testContainersPostgreSQLVersion = "1.19.7"
17-
1814
dependencies {
1915
implementation(projects.cosmotechMetaApi)
2016
implementation(projects.cosmotechConnectorApi)

api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders
3434
import org.springframework.web.context.WebApplicationContext
3535
import org.testcontainers.containers.PostgreSQLContainer
3636
import org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT
37+
import org.testcontainers.containers.localstack.LocalStackContainer
3738
import org.testcontainers.junit.jupiter.Testcontainers
39+
import org.testcontainers.utility.DockerImageName
3840
import org.testcontainers.utility.MountableFile
3941

4042
@Testcontainers
@@ -99,7 +101,8 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
99101
private const val READER_USER_CREDENTIALS = "readusertest"
100102
private const val WRITER_USER_CREDENTIALS = "writeusertest"
101103
private const val DEFAULT_REDIS_PORT = 6379
102-
private const val REDIS_STACK_LASTEST_TAG_WITH_GRAPH = "6.2.6-v18"
104+
private const val REDIS_STACK_LATEST_TAG_WITH_GRAPH = "6.2.6-v18"
105+
private const val LOCALSTACK_FULL_IMAGE_NAME = "localstack/localstack:3.5.0"
103106

104107
var postgres: PostgreSQLContainer<*> =
105108
PostgreSQLContainer("postgres:alpine3.19")
@@ -108,18 +111,25 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
108111

109112
var redisStackServer =
110113
RedisStackContainer(
111-
RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(REDIS_STACK_LASTEST_TAG_WITH_GRAPH))
114+
RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(REDIS_STACK_LATEST_TAG_WITH_GRAPH))
115+
116+
val localStackServer =
117+
LocalStackContainer(DockerImageName.parse(LOCALSTACK_FULL_IMAGE_NAME))
118+
.withServices(LocalStackContainer.Service.S3)
112119

113120
init {
114121
redisStackServer.start()
115122
postgres.start()
123+
localStackServer.start()
124+
localStackServer.execInContainer("awslocal", "s3", "mb", "s3://test-bucket")
116125
}
117126

118127
@JvmStatic
119128
@DynamicPropertySource
120129
fun connectionProperties(registry: DynamicPropertyRegistry) {
121130
initPostgresConfiguration(registry)
122131
initRedisConfiguration(registry)
132+
initS3Configuration(registry)
123133
}
124134

125135
private fun initRedisConfiguration(registry: DynamicPropertyRegistry) {
@@ -133,6 +143,13 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
133143
registry.add("spring.data.redis.port") { DEFAULT_REDIS_PORT }
134144
}
135145

146+
private fun initS3Configuration(registry: DynamicPropertyRegistry) {
147+
registry.add("spring.cloud.aws.s3.endpoint") { localStackServer.endpoint }
148+
registry.add("spring.cloud.aws.credentials.access-key") { localStackServer.accessKey }
149+
registry.add("spring.cloud.aws.credentials.secret-key") { localStackServer.secretKey }
150+
registry.add("spring.cloud.aws.s3.region") { localStackServer.region }
151+
}
152+
136153
private fun initPostgresConfiguration(registry: DynamicPropertyRegistry) {
137154
registry.add("csm.platform.internalResultServices.storage.host") { postgres.host }
138155
registry.add("csm.platform.internalResultServices.storage.port") {

api/src/integrationTest/resources/application-test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
client-type: jedis
1313
main:
1414
banner-mode: "off"
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
csm:
1731
platform:
@@ -105,5 +119,10 @@ csm:
105119
default-page-size: 5
106120
rbac:
107121
enabled: true
122+
s3:
123+
endpointUrl: "http://localhost:9000"
124+
bucketName: "test-bucket"
125+
accessKeyId: "s3_username"
126+
secretAccessKey: "s3_password"
108127

109128

build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val springWebVersion = "6.2.1"
6161

6262
// Implementation
6363
val kotlinJvmTarget = 21
64-
val cosmotechApiCommonVersion = "2.1.1-LCRA-store_workspace_files_in_seaweed_PROD-14290-SNAPSHOT"
64+
val cosmotechApiCommonVersion = "2.1.0-SNAPSHOT"
6565
val jedisVersion = "4.4.6"
6666
val springOauthVersion = "6.4.2"
6767
val redisOmSpringVersion = "0.9.7"
@@ -77,7 +77,8 @@ val orgJsonVersion = "20240303"
7777
val jacksonModuleKotlinVersion = "2.18.3"
7878
val testNgVersion = "7.8.0"
7979
val testContainersRedisVersion = "1.6.4"
80-
val testContainersPostgreSQLVersion = "1.19.7"
80+
val testContainersPostgreSQLVersion = "1.20.6"
81+
val testContainersLocalStackVersion = "1.20.6"
8182
val commonCompressVersion = "1.27.1"
8283
val awsSpringVersion = "3.1.1"
8384

@@ -141,7 +142,6 @@ allprojects {
141142
configurations { all { resolutionStrategy { force("com.redis.om:redis-om-spring:0.9.1") } } }
142143

143144
repositories {
144-
mavenLocal()
145145
maven {
146146
name = "GitHubPackages"
147147
url = uri("https://maven.pkg.github.com/Cosmo-Tech/cosmotech-api-common")
@@ -327,6 +327,7 @@ subprojects {
327327
testImplementation(
328328
"com.redis.testcontainers:testcontainers-redis-junit:$testContainersRedisVersion")
329329
testImplementation("org.testcontainers:postgresql:$testContainersPostgreSQLVersion")
330+
testImplementation("org.testcontainers:localstack:$testContainersLocalStackVersion")
330331
testImplementation("org.springframework.boot:spring-boot-starter-test")
331332

332333
integrationTestImplementation("org.springframework.boot:spring-boot-starter-test") {

connector/src/integrationTest/resources/application-connector-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
client-type: jedis
1313
main:
1414
banner-mode: "off"
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
csm:
1731
platform:

dataset/src/integrationTest/resources/application-dataset-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
client-type: jedis
1313
main:
1414
banner-mode: "off"
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
csm:
1731
platform:

organization/src/integrationTest/resources/application-organization-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
client-type: jedis
1313
main:
1414
banner-mode: "off"
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
csm:
1731
platform:

run/src/integrationTest/resources/application-run-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
# Leave it as blank as there's no auth with test container
1313
password:
1414
client-type: jedis
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
logging:
1731
level:

runner/src/integrationTest/resources/application-runner-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ spring:
88
client-type: jedis
99
main:
1010
banner-mode: "off"
11+
cloud:
12+
aws:
13+
credentials:
14+
access-key: "accessKeyId"
15+
secret-key: "secretAccessKey"
16+
s3:
17+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
18+
region: "region"
19+
# Enable path-style / disable DNS-style
20+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
21+
# which is not how our current S3 implementation works as it expects the bucket in the path
22+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
23+
path-style-access-enabled: true
24+
endpoint: "http://localhost:9000"
1125

1226
management:
1327
endpoints:

solution/src/integrationTest/resources/application-solution-test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ spring:
1212
client-type: jedis
1313
main:
1414
banner-mode: "off"
15+
cloud:
16+
aws:
17+
credentials:
18+
access-key: "accessKeyId"
19+
secret-key: "secretAccessKey"
20+
s3:
21+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
22+
region: "region"
23+
# Enable path-style / disable DNS-style
24+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
25+
# which is not how our current S3 implementation works as it expects the bucket in the path
26+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
27+
path-style-access-enabled: true
28+
endpoint: "http://localhost:9000"
1529

1630
csm:
1731
platform:
@@ -104,3 +118,4 @@ csm:
104118
bucketName: "test-bucket"
105119
accessKeyId: "s3_username"
106120
secretAccessKey: "s3_password"
121+
region: "us-east-1"

0 commit comments

Comments
 (0)