File tree Expand file tree Collapse file tree
main/kotlin/io/sdkman/broker/config
test/kotlin/io/sdkman/broker/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,12 +48,11 @@ class DefaultAppConfig : AppConfig {
4848
4949 // Persistence backend selector
5050 override val persistenceBackend: PersistenceBackend =
51- config.getStringOrDefault(" persistence.backend" , PersistenceBackend .Mongo .configValue).let { raw ->
52- PersistenceBackend .fromConfigValue(raw).getOrElse {
51+ config.getOptionString(" persistence.backend" )
52+ .flatMap { PersistenceBackend .fromConfigValue(it) }
53+ .getOrElse {
5354 throw IllegalArgumentException (
54- " Invalid PERSISTENCE_BACKEND value '$raw '. " +
55- " Supported values: ${PersistenceBackend .supportedValues.joinToString(" , " )} ."
55+ " PERSISTENCE_BACKEND value not found or incorrect. Supported values: mongo, postgres."
5656 )
5757 }
58- }
5958}
Original file line number Diff line number Diff line change 11package io.sdkman.broker.config
22
33import arrow.core.Option
4- import arrow.core.toOption
4+ import arrow.core.getOrNone
55
66enum class PersistenceBackend (
77 val configValue : String
@@ -13,8 +13,6 @@ enum class PersistenceBackend(
1313 private val configValueToBackend: Map <String , PersistenceBackend > =
1414 entries.associateBy { it.configValue }
1515
16- fun fromConfigValue (value : String ): Option <PersistenceBackend > = configValueToBackend[value].toOption()
17-
18- val supportedValues: List <String > = entries.map { it.configValue }
16+ fun fromConfigValue (value : String ): Option <PersistenceBackend > = configValueToBackend.getOrNone(value)
1917 }
2018}
Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ class AppConfigSpec :
126126
127127 // when/then: construction must blow up so the broker never serves traffic against an unsupported backend
128128 val error = shouldThrow<IllegalArgumentException > { DefaultAppConfig () }
129- error.message shouldContain " cassandra"
130- error.message shouldContain " mongo"
131- error.message shouldContain " postgres"
129+ error.message shouldContain " PERSISTENCE_BACKEND value not found or incorrect."
130+ error.message shouldContain " Supported values: mongo, postgres."
132131 }
133132 })
You can’t perform that action at this time.
0 commit comments