problem: tries to connect to Redis even if specified as disabled

This commit is contained in:
Igor Artamonov
2020-06-29 21:49:01 -04:00
parent 03b6d6472c
commit 04958784ec
3 changed files with 33 additions and 12 deletions

View File

@@ -35,6 +35,8 @@ class CacheConfigReader : YamlConfigReader(), ConfigReader<CacheConfig> {
val config = CacheConfig() val config = CacheConfig()
getMapping(node, "redis")?.let { node -> getMapping(node, "redis")?.let { node ->
val redis = CacheConfig.Redis() val redis = CacheConfig.Redis()
val enabled = getValueAsBool(node, "enabled") ?: true
if (enabled) {
getValueAsString(node, "host")?.let { getValueAsString(node, "host")?.let {
redis.host = it redis.host = it
} }
@@ -49,6 +51,7 @@ class CacheConfigReader : YamlConfigReader(), ConfigReader<CacheConfig> {
} }
config.redis = redis config.redis = redis
} }
}
if (config.redis == null) { if (config.redis == null) {
return null return null
} }

View File

@@ -36,4 +36,15 @@ class CacheConfigReaderSpec extends Specification {
password == "HelloWorld!1" password == "HelloWorld!1"
} }
} }
def "Read disabled"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("cache-redis-disabled.yaml")
when:
def act = reader.read(config)
then:
//later may be not null if we support something else besides Redis
act == null
}
} }

View File

@@ -0,0 +1,7 @@
cache:
redis:
enabled: false
host: redis-master
port: 1234
db: 5
password: HelloWorld!1