mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-21 17:01:04 +01:00
test(config): check loading arr from env
This commit is contained in:
parent
821601c1da
commit
bd77762d4f
@ -30,6 +30,7 @@ func TestLoadEnvironmentToObject(t *testing.T) {
|
||||
Subfield struct {
|
||||
Value string `env:"TEST_VALUE_ENV_VAR"`
|
||||
}
|
||||
StringArr []string `env:"TEST_STRING_ARR"`
|
||||
}
|
||||
|
||||
err := os.Setenv("TEST_FLAG", "yes")
|
||||
@ -47,6 +48,11 @@ func TestLoadEnvironmentToObject(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Setenv("TEST_STRING_ARR", "[\"test1\",\"test2\"]")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = loadEnvironmentToObject(&val)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -63,6 +69,18 @@ func TestLoadEnvironmentToObject(t *testing.T) {
|
||||
if val.Subfield.Value != "test_value" {
|
||||
t.Error("Invalid value")
|
||||
}
|
||||
|
||||
if val.StringArr == nil {
|
||||
t.Error("Invalid array value")
|
||||
}
|
||||
|
||||
if val.StringArr[0] != "test1" {
|
||||
t.Error("Invalid array item value")
|
||||
}
|
||||
|
||||
if val.StringArr[1] != "test2" {
|
||||
t.Error("Invalid array item value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastStringToInt(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user