[#577] cmd/node: Add tests for boolean type casting in config

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-01 19:24:44 +03:00 committed by Alex Vanin
parent ed80f704d0
commit 52c82ef46a
3 changed files with 33 additions and 0 deletions

View file

@ -63,6 +63,25 @@ func TestDuration(t *testing.T) {
})
}
func TestBool(t *testing.T) {
configtest.ForEachFileType("test/config", func(c *config.Config) {
c = c.Sub("bool")
val := config.Bool(c, "correct")
require.Equal(t, true, val)
val = config.Bool(c, "correct_string")
require.Equal(t, true, val)
require.Panics(t, func() {
config.Bool(c, "incorrect")
})
val = config.BoolSafe(c, "incorrect")
require.Equal(t, false, val)
})
}
func TestNumbers(t *testing.T) {
configtest.ForEachFileType("test/config", func(c *config.Config) {
c = c.Sub("number")

View file

@ -23,19 +23,28 @@
],
"incorrect": null
},
"string": {
"correct": "some string",
"incorrect": []
},
"duration": {
"correct": "15m",
"incorrect": "some string"
},
"number": {
"int_pos": 1,
"int_neg": -1,
"fract_pos": 2.5,
"fract_neg": -2.5,
"incorrect": "some string"
},
"bool": {
"correct": true,
"correct_string": "true",
"incorrect": "not true"
}
}

View file

@ -35,3 +35,8 @@ number:
fract_pos: 2.5
fract_neg: -2.5
incorrect: some string
bool:
correct: true
correct_string: "true"
incorrect: not true