Skip to content

Commit

Permalink
test(config): check loading arr from env
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Oct 24, 2024
1 parent 821601c commit bd77762
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions util/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit bd77762

Please sign in to comment.