test(config): check loading arr from env

This commit is contained in:
Denis Gukov 2024-10-24 18:28:51 +00:00
parent 821601c1da
commit bd77762d4f

View File

@ -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) {