189 lines
3.1 KiB
V
189 lines
3.1 KiB
V
module conf
|
|
|
|
struct SingleConf {
|
|
some_int int
|
|
}
|
|
|
|
struct SingleConfDefault {
|
|
some_int int = 2
|
|
}
|
|
|
|
fn test_int_present_no_default() {
|
|
mut conf := load[SingleConf](default_path: 'test/int.toml')!
|
|
assert conf == SingleConf{
|
|
some_int: 1
|
|
}
|
|
|
|
conf = load[SingleConf](default_path: 'test/int_zero.toml')!
|
|
assert conf == SingleConf{
|
|
some_int: 0
|
|
}
|
|
}
|
|
|
|
fn test_int_present_no_default_env() {
|
|
mut conf := load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': '3'
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 3
|
|
}
|
|
|
|
conf = load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 0
|
|
}
|
|
|
|
conf = load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'TEST_SOME_INT': '3'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 3
|
|
}
|
|
}
|
|
|
|
fn test_int_absent_no_default() {
|
|
conf := load[SingleConf](default_path: 'test/empty.toml') or { return }
|
|
assert false
|
|
}
|
|
|
|
fn test_int_absent_no_default_env() {
|
|
mut conf := load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': '3'
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 3
|
|
}
|
|
|
|
conf = load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 0
|
|
}
|
|
|
|
conf = load[SingleConf](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'TEST_SOME_INT': '3'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConf{
|
|
some_int: 3
|
|
}
|
|
}
|
|
|
|
fn test_int_present_default() {
|
|
conf := load[SingleConfDefault](default_path: 'test/int.toml')!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 1
|
|
}
|
|
}
|
|
|
|
fn test_int_present_default_env() {
|
|
mut conf := load[SingleConfDefault](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': '3'
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 3
|
|
}
|
|
|
|
conf = load[SingleConfDefault](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'SOME_INT': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 0
|
|
}
|
|
|
|
conf = load[SingleConfDefault](
|
|
default_path: 'test/int.toml'
|
|
env: {
|
|
'TEST_SOME_INT': '3'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 3
|
|
}
|
|
}
|
|
|
|
fn test_int_absent_default() {
|
|
conf := load[SingleConfDefault](default_path: 'test/empty.toml')!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 2
|
|
}
|
|
}
|
|
|
|
fn test_int_absent_default_env() {
|
|
mut conf := load[SingleConfDefault](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_INT': '3'
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 3
|
|
}
|
|
|
|
conf = load[SingleConfDefault](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_INT': ''
|
|
}
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 0
|
|
}
|
|
|
|
conf = load[SingleConfDefault](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'TEST_SOME_INT': '3'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf == SingleConfDefault{
|
|
some_int: 3
|
|
}
|
|
}
|
|
|
|
struct SingleConfDefaultEmpty {
|
|
some_int int [empty_default]
|
|
}
|
|
|
|
fn test_int_absent_default_empty() {
|
|
conf := load[SingleConfDefaultEmpty](default_path: 'test/empty.toml')!
|
|
assert conf == SingleConfDefaultEmpty{
|
|
some_int: 0
|
|
}
|
|
}
|
|
|
|
// fn test_int_wrong_type() {
|
|
// conf := load<SingleConf>(default_path: 'test/int_wrong_type.toml') or { return }
|
|
// assert false
|
|
//}
|