-
Notifications
You must be signed in to change notification settings - Fork 12
/
Options.kt
83 lines (74 loc) · 3.27 KB
/
Options.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.trendyol.stove.testing.e2e.elasticsearch
import arrow.core.None
import arrow.core.Option
import arrow.core.none
import co.elastic.clients.elasticsearch.ElasticsearchClient
import com.fasterxml.jackson.databind.ObjectMapper
import com.trendyol.stove.testing.e2e.containers.ExposedCertificate
import com.trendyol.stove.testing.e2e.database.migrations.DatabaseMigration
import com.trendyol.stove.testing.e2e.database.migrations.MigrationCollection
import com.trendyol.stove.testing.e2e.serialization.StoveObjectMapper
import com.trendyol.stove.testing.e2e.system.abstractions.ConfiguresExposedConfiguration
import com.trendyol.stove.testing.e2e.system.abstractions.ExposedConfiguration
import com.trendyol.stove.testing.e2e.system.abstractions.SystemOptions
import org.apache.http.client.config.RequestConfig
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import org.elasticsearch.client.RestClient
import org.testcontainers.elasticsearch.ElasticsearchContainer
import javax.net.ssl.SSLContext
import kotlin.time.Duration.Companion.minutes
data class ElasticsearchSystemOptions(
val defaultIndex: DefaultIndex,
val clientConfigurer: ElasticClientConfigurer = ElasticClientConfigurer(),
val containerOptions: ContainerOptions = ContainerOptions(),
val objectMapper: ObjectMapper = StoveObjectMapper.Default,
override val configureExposedConfiguration: (ElasticSearchExposedConfiguration) -> List<String> = { _ -> listOf() }
) : SystemOptions, ConfiguresExposedConfiguration<ElasticSearchExposedConfiguration> {
internal val migrationCollection: MigrationCollection<ElasticsearchClient> = MigrationCollection()
/**
* Helps for registering migrations before the tests run.
* @see MigrationCollection
* @see DatabaseMigration
*/
fun migrations(migration: MigrationCollection<ElasticsearchClient>.() -> Unit): ElasticsearchSystemOptions = migration(
migrationCollection
).let {
this
}
}
data class ElasticsearchExposedCertificate(
val bytes: ByteArray,
val sslContext: SSLContext
) : ExposedCertificate
data class ElasticSearchExposedConfiguration(
val host: String,
val port: Int,
val password: String,
val certificate: ExposedCertificate
) : ExposedConfiguration
data class ElasticsearchContext(
val index: String,
val container: ElasticsearchContainer,
val options: ElasticsearchSystemOptions
)
data class ContainerOptions(
val registry: String = "docker.elastic.co/",
val imageVersion: String = "8.6.1",
val compatibleSubstitute: Option<String> = None,
val exposedPorts: List<Int> = listOf(9200),
val password: String = "password",
val disableSecurity: Boolean = true,
val configureContainer: ElasticsearchContainer.() -> Unit = {}
)
data class ElasticClientConfigurer(
val httpClientBuilder: HttpAsyncClientBuilder.() -> Unit = {
setDefaultRequestConfig(
RequestConfig.custom()
.setSocketTimeout(5.minutes.inWholeMilliseconds.toInt())
.setConnectTimeout(5.minutes.inWholeMilliseconds.toInt())
.setConnectionRequestTimeout(5.minutes.inWholeMilliseconds.toInt())
.build()
)
},
val restClientOverrideFn: Option<(cfg: ElasticSearchExposedConfiguration) -> RestClient> = none()
)