-
Notifications
You must be signed in to change notification settings - Fork 162
/
WispConfigTest.kt
133 lines (111 loc) · 3.82 KB
/
WispConfigTest.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package wisp.config
import com.sksamuel.hoplite.Masked
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
internal class WispConfigTest {
data class MyConfig(
val foo: Foo,
val baz: String
) : Config
data class Foo(
val enabled: Boolean,
val bar: Int
)
data class AWSCredentials (
val AWS_ACCESS_KEY_ID: Masked,
val AWS_SECRET_ACCESS_KEY: Masked
) : Config
data class AWSConfigYaml (
val aws: AWSCredentials
) : Config
@Test
fun `config for a single config file loads`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(ConfigSource("classpath:/a.yaml"))
)
val myConfig = builder.build().loadConfigOrThrow<MyConfig>()
assertTrue(myConfig.foo.enabled)
assertEquals(72, myConfig.foo.bar)
assertEquals("abc", myConfig.baz)
}
@Test
fun `config for a two config file loads with correct override`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(
ConfigSource("classpath:/b.yaml"),
ConfigSource("classpath:/a.yaml")
)
)
val myConfig = builder.build().loadConfigOrThrow<MyConfig>()
assertFalse(myConfig.foo.enabled)
assertEquals(72, myConfig.foo.bar)
assertEquals("abc", myConfig.baz)
}
@Test
fun `config for a multiple config files loads with correct override`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(
ConfigSource("classpath:/c.yaml"),
ConfigSource("classpath:/b.yaml"),
ConfigSource("classpath:/a.yaml")
)
)
val myConfig = builder.build().loadConfigOrThrow<MyConfig>()
assertFalse(myConfig.foo.enabled)
assertEquals(11, myConfig.foo.bar)
assertEquals("xyz", myConfig.baz)
}
@Test
fun `config for a multiple config files with some not existing, loads with correct override`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(
ConfigSource("classpath:/do_not_exist.yaml"),
ConfigSource("classpath:/c.yaml"),
ConfigSource("classpath:/b.yaml"),
ConfigSource("classpath:/a.yaml")
)
)
val myConfig = builder.build().loadConfigOrThrow<MyConfig>()
assertFalse(myConfig.foo.enabled)
assertEquals(11, myConfig.foo.bar)
assertEquals("xyz", myConfig.baz)
}
@Test
fun `config for a aws credential yaml file loads with correct values and should be masked`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(
ConfigSource("classpath:/aws.yaml"),
)
)
val myConfig = builder.build().loadConfigOrThrow<AWSConfigYaml>()
assertEquals("AAAAAAAAAAAAAAAA", myConfig.aws.AWS_ACCESS_KEY_ID.value)
assertEquals("RRRRRRRRRRRRRRRRR", myConfig.aws.AWS_SECRET_ACCESS_KEY.value)
// values should me masked
assertNotEquals("AAAAAAAAAAAAAAAA", myConfig.aws.AWS_ACCESS_KEY_ID.toString())
assertNotEquals("RRRRRRRRRRRRRRRRR", myConfig.aws.AWS_SECRET_ACCESS_KEY.toString())
}
@Test
fun `config for a aws credential properties file loads with correct values and should be masked`() {
val builder = WispConfig.builder()
builder.addWispConfigSources(
listOf(
ConfigSource("classpath:/aws_credentials", "props"),
)
)
val myConfig = builder.build().loadConfigOrThrow<AWSCredentials>()
assertEquals("AAAAAAAAAAAAAAAA", myConfig.AWS_ACCESS_KEY_ID.value)
assertEquals("RRRRRRRRRRRRRRRRR", myConfig.AWS_SECRET_ACCESS_KEY.value)
// values should me masked
assertNotEquals("AAAAAAAAAAAAAAAA", myConfig.AWS_ACCESS_KEY_ID.toString())
assertNotEquals("RRRRRRRRRRRRRRRRR", myConfig.AWS_SECRET_ACCESS_KEY.toString())
}
// TODO(chrisryan): add tests to support other formats
}