184 lines
3.2 KiB
V
184 lines
3.2 KiB
V
module conf
|
|
|
|
struct SingleConf {
|
|
some_string string
|
|
}
|
|
|
|
struct SingleConfDefault {
|
|
some_string string = 'default'
|
|
}
|
|
|
|
fn test_string_present_no_default() {
|
|
conf := load<SingleConf>(default_path: 'test/string.toml')!
|
|
assert conf == SingleConf{
|
|
some_string: 'hi'
|
|
}
|
|
|
|
conf2 := load<SingleConf>(default_path: 'test/string_empty.toml')!
|
|
assert conf2 == SingleConf{
|
|
some_string: ''
|
|
}
|
|
}
|
|
|
|
fn test_string_present_no_default_env() {
|
|
mut conf := load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': 'env'
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: 'env'
|
|
}
|
|
|
|
conf = load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: ''
|
|
}
|
|
|
|
conf = load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'TEST_SOME_STRING': 'env'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: 'env'
|
|
}
|
|
}
|
|
|
|
fn test_string_absent_no_default() {
|
|
conf := load<SingleConf>(default_path: 'test/empty.toml') or { return }
|
|
assert false
|
|
}
|
|
|
|
fn test_string_absent_no_default_env() {
|
|
mut conf := load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': 'env'
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: 'env'
|
|
}
|
|
|
|
conf = load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: ''
|
|
}
|
|
|
|
conf = load<SingleConf>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'TEST_SOME_STRING': 'env'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_string: 'env'
|
|
}
|
|
}
|
|
|
|
fn test_string_present_default() {
|
|
conf := load<SingleConfDefault>(default_path: 'test/string.toml')!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'hi'
|
|
}
|
|
}
|
|
|
|
fn test_string_present_default_env() {
|
|
mut conf := load<SingleConfDefault>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': 'env'
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'env'
|
|
}
|
|
|
|
conf = load<SingleConfDefault>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'SOME_STRING': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: ''
|
|
}
|
|
|
|
conf = load<SingleConfDefault>(
|
|
default_path: 'test/string.toml'
|
|
env: {
|
|
'TEST_SOME_STRING': 'env'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'env'
|
|
}
|
|
}
|
|
|
|
fn test_string_absent_default() {
|
|
conf := load<SingleConfDefault>(default_path: 'test/empty.toml')!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'default'
|
|
}
|
|
}
|
|
|
|
fn test_string_absent_default_env() {
|
|
mut conf := load<SingleConfDefault>(
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_STRING': 'env'
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'env'
|
|
}
|
|
|
|
conf = load<SingleConfDefault>(
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_STRING': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: ''
|
|
}
|
|
|
|
conf = load<SingleConfDefault>(
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'TEST_SOME_STRING': 'env'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_string: 'env'
|
|
}
|
|
}
|
|
|
|
struct SingleConfDefaultEmpty {
|
|
some_string string [empty_default]
|
|
}
|
|
|
|
fn test_string_absent_default_empty() {
|
|
conf := load<SingleConfDefaultEmpty>(default_path: 'test/empty.toml')!
|
|
assert conf == SingleConfDefaultEmpty{
|
|
some_string: ''
|
|
}
|
|
}
|