problem: reading yaml to both plain properties and structured objects is a mess
solution: use just objects for configs
This commit is contained in:
@@ -31,7 +31,7 @@ class TlsSetupSpec extends Specification {
|
||||
enabled: false
|
||||
)
|
||||
when:
|
||||
def act = tlsSetup.setupServer("test", config)
|
||||
def act = tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
act == null
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class TlsSetupSpec extends Specification {
|
||||
key: "127.0.0.1.p8.key"
|
||||
)
|
||||
when:
|
||||
def act = tlsSetup.setupServer("test", config)
|
||||
def act = tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
act != null
|
||||
act.server
|
||||
@@ -67,7 +67,7 @@ class TlsSetupSpec extends Specification {
|
||||
clientCa: "ca.myhost.dev.crt"
|
||||
)
|
||||
when:
|
||||
def act = tlsSetup.setupServer("test", config)
|
||||
def act = tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
act != null
|
||||
act.server
|
||||
@@ -87,7 +87,7 @@ class TlsSetupSpec extends Specification {
|
||||
key: "127.0.0.1.p8.key",
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
t.message == "Certificate not set"
|
||||
@@ -100,7 +100,7 @@ class TlsSetupSpec extends Specification {
|
||||
certificate: "127.0.0.1.crt"
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
t.message == "Certificate Key not set"
|
||||
@@ -114,7 +114,7 @@ class TlsSetupSpec extends Specification {
|
||||
key: "127.0.0.1.p8.key",
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
@@ -127,7 +127,7 @@ class TlsSetupSpec extends Specification {
|
||||
key: "none.p8.key",
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class TlsSetupSpec extends Specification {
|
||||
key: "127.0.0.1.key",
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class TlsSetupSpec extends Specification {
|
||||
clientRequire: true
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class TlsSetupSpec extends Specification {
|
||||
clientCa: "none.crt"
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class TlsSetupSpec extends Specification {
|
||||
clientCa: "ca.myhost.dev.key"
|
||||
)
|
||||
when:
|
||||
tlsSetup.setupServer("test", config)
|
||||
tlsSetup.setupServer("test", config, false)
|
||||
then:
|
||||
def t = thrown(IllegalArgumentException)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.emeraldpay.dshackle.config
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
class CacheConfigReaderSpec extends Specification {
|
||||
|
||||
CacheConfigReader reader = new CacheConfigReader()
|
||||
|
||||
def "Read full"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("cache-redis-full.yaml")
|
||||
when:
|
||||
def act = reader.read(config)
|
||||
|
||||
then:
|
||||
act.redis != null
|
||||
with(act.redis) {
|
||||
host == "redis-master"
|
||||
port == 1234
|
||||
db == 5
|
||||
password == "HelloWorld!1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package io.emeraldpay.dshackle.config
|
||||
|
||||
import io.emeraldpay.dshackle.FileResolver
|
||||
import io.emeraldpay.dshackle.test.TestingCommons
|
||||
import io.emeraldpay.grpc.Chain
|
||||
import spock.lang.Specification
|
||||
|
||||
class MainConfigReaderSpec extends Specification {
|
||||
|
||||
MainConfigReader reader = new MainConfigReader(TestingCommons.fileResolver())
|
||||
|
||||
def "Read full config"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("dshackle-full.yaml")
|
||||
when:
|
||||
def act = reader.read(config)
|
||||
|
||||
then:
|
||||
act != null
|
||||
act.host == "192.168.1.101"
|
||||
act.port == 2448
|
||||
act.tls != null
|
||||
with(act.tls) {
|
||||
certificate == "/path/127.0.0.1.crt"
|
||||
key == "/path/127.0.0.1.p8.key"
|
||||
!clientRequire
|
||||
clientCa == "/path/ca.dshackle.test.crt"
|
||||
}
|
||||
act.cache != null
|
||||
with(act.cache) {
|
||||
redis != null
|
||||
redis.host == "redis-master"
|
||||
}
|
||||
act.proxy != null
|
||||
with(act.proxy) {
|
||||
port == 8082
|
||||
tls != null
|
||||
routes != null
|
||||
routes.size() == 3
|
||||
with(routes[0]) {
|
||||
id == "eth"
|
||||
blockchain == Chain.ETHEREUM
|
||||
}
|
||||
with(routes[1]) {
|
||||
id == "etc"
|
||||
blockchain == Chain.ETHEREUM_CLASSIC
|
||||
}
|
||||
with(routes[2]) {
|
||||
id == "kovan"
|
||||
blockchain == Chain.TESTNET_KOVAN
|
||||
}
|
||||
}
|
||||
act.upstreams != null
|
||||
with(act.upstreams) {
|
||||
defaultOptions != null
|
||||
defaultOptions.size() == 1
|
||||
with(defaultOptions[0]) {
|
||||
chains == ["ethereum"]
|
||||
options.minPeers == 3
|
||||
}
|
||||
upstreams.size() == 3
|
||||
with(upstreams[0]) {
|
||||
id == "remote"
|
||||
}
|
||||
with(upstreams[1]) {
|
||||
id == "local"
|
||||
}
|
||||
with(upstreams[2]) {
|
||||
id == "infura"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import spock.lang.Specification
|
||||
|
||||
class UpstreamsConfigReaderSpec extends Specification {
|
||||
|
||||
UpstreamsConfigReader reader = new UpstreamsConfigReader()
|
||||
UpstreamsConfigReader reader = new UpstreamsConfigReader(TestingCommons.fileResolver())
|
||||
|
||||
def "Parse standard config"() {
|
||||
setup:
|
||||
@@ -32,7 +32,6 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
def act = reader.read(config)
|
||||
then:
|
||||
act != null
|
||||
act.version == "v1"
|
||||
with(act.defaultOptions) {
|
||||
size() == 1
|
||||
with(get(0)) {
|
||||
@@ -81,7 +80,6 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
def act = reader.read(config)
|
||||
then:
|
||||
act != null
|
||||
act.version == "v1"
|
||||
act.upstreams.size() == 1
|
||||
with(act.upstreams.get(0)) {
|
||||
id == "remote"
|
||||
@@ -141,7 +139,6 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
def act = reader.read(config)
|
||||
then:
|
||||
act != null
|
||||
act.version == "v1"
|
||||
with(act.defaultOptions) {
|
||||
size() == 0
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import io.emeraldpay.dshackle.FileResolver
|
||||
import io.emeraldpay.dshackle.cache.Caches
|
||||
import io.emeraldpay.dshackle.cache.CachesFactory
|
||||
import io.emeraldpay.dshackle.config.CacheConfig
|
||||
import io.emeraldpay.dshackle.upstream.AggregatedUpstream
|
||||
import io.emeraldpay.dshackle.upstream.ChainUpstreams
|
||||
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
||||
@@ -78,7 +79,7 @@ class TestingCommons {
|
||||
}
|
||||
|
||||
static CachesFactory emptyCaches() {
|
||||
return new CachesFactory(objectMapper(), new StandardEnvironment())
|
||||
return new CachesFactory(objectMapper(), new CacheConfig())
|
||||
}
|
||||
|
||||
static FileResolver fileResolver() {
|
||||
|
||||
Reference in New Issue
Block a user