2022-12-28 18:57:10 +01:00
|
|
|
module conf
|
|
|
|
|
|
|
|
struct SingleConf {
|
|
|
|
some_int int
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SingleConfDefault {
|
|
|
|
some_int int = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_present_no_default() {
|
2023-02-08 10:40:37 +01:00
|
|
|
mut conf := load[SingleConf](default_path: 'test/int.toml')!
|
2022-12-28 18:57:10 +01:00
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 1
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConf](default_path: 'test/int_zero.toml')!
|
2022-12-28 18:57:10 +01:00
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_present_no_default_env() {
|
2023-02-08 10:40:37 +01:00
|
|
|
mut conf := load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': '3'
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': ''
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'TEST_SOME_INT': '3'
|
|
|
|
}
|
|
|
|
prefix: 'TEST_'
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_absent_no_default() {
|
2023-02-08 10:40:37 +01:00
|
|
|
conf := load[SingleConf](default_path: 'test/empty.toml') or { return }
|
2022-12-28 18:57:10 +01:00
|
|
|
assert false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_absent_no_default_env() {
|
2023-02-08 10:40:37 +01:00
|
|
|
mut conf := load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': '3'
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': ''
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConf](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'TEST_SOME_INT': '3'
|
|
|
|
}
|
|
|
|
prefix: 'TEST_'
|
|
|
|
)!
|
|
|
|
assert conf == SingleConf{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_present_default() {
|
2023-02-08 10:40:37 +01:00
|
|
|
conf := load[SingleConfDefault](default_path: 'test/int.toml')!
|
2022-12-28 18:57:10 +01:00
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_present_default_env() {
|
2023-02-08 10:40:37 +01:00
|
|
|
mut conf := load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': '3'
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': ''
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/int.toml'
|
|
|
|
env: {
|
|
|
|
'TEST_SOME_INT': '3'
|
|
|
|
}
|
|
|
|
prefix: 'TEST_'
|
|
|
|
)!
|
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_absent_default() {
|
2023-02-08 10:40:37 +01:00
|
|
|
conf := load[SingleConfDefault](default_path: 'test/empty.toml')!
|
2022-12-28 18:57:10 +01:00
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_int_absent_default_env() {
|
2023-02-08 10:40:37 +01:00
|
|
|
mut conf := load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/empty.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': '3'
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 3
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
default_path: 'test/empty.toml'
|
|
|
|
env: {
|
|
|
|
'SOME_INT': ''
|
|
|
|
}
|
|
|
|
)!
|
|
|
|
assert conf == SingleConfDefault{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:40:37 +01:00
|
|
|
conf = load[SingleConfDefault](
|
2022-12-28 18:57:10 +01:00
|
|
|
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() {
|
2023-02-08 10:40:37 +01:00
|
|
|
conf := load[SingleConfDefaultEmpty](default_path: 'test/empty.toml')!
|
2022-12-28 18:57:10 +01:00
|
|
|
assert conf == SingleConfDefaultEmpty{
|
|
|
|
some_int: 0
|
|
|
|
}
|
|
|
|
}
|
2022-12-28 19:43:10 +01:00
|
|
|
|
2022-12-28 20:04:45 +01:00
|
|
|
// fn test_int_wrong_type() {
|
|
|
|
// conf := load<SingleConf>(default_path: 'test/int_wrong_type.toml') or { return }
|
|
|
|
// assert false
|
|
|
|
//}
|