add slice support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-12-04 21:52:21 +03:00
parent 7badb91465
commit 19fefe591c
2 changed files with 158 additions and 87 deletions

View File

@@ -6,12 +6,14 @@ import (
"testing"
"context"
"os"
"fmt"
)
type Config struct {
StringValue string `env:"STRING_VALUE"`
BoolValue bool `env:"BOOL_VALUE"`
StringSlice []string `env:"STRING_SLICE"`
IntSlice []int `env:"INT_SLICE"`
}
func TestEnv(t *testing.T) {
@@ -34,7 +36,8 @@ func TestEnv(t *testing.T) {
os.Setenv("STRING_VALUE","STRING_VALUE")
os.Setenv("BOOL_VALUE","true")
os.Setenv("STRING_SLICE", "STRING_SLICE1,STRING_SLICE2")
os.Setenv("STRING_SLICE", "STRING_SLICE1,STRING_SLICE2;STRING_SLICE3")
os.Setenv("INT_SLICE", "1,2,3,4,5")
if err := cfg.Load(ctx); err !=nil {
t.Fatal(err)
@@ -47,7 +50,9 @@ func TestEnv(t *testing.T) {
t.Fatalf("something wrong with env config: %v", conf)
}
if len(conf.StringSlice) != 2 {
if len(conf.StringSlice) != 3 {
t.Fatalf("something wrong with env config: %v", conf)
}
fmt.Printf("%#+v\n", conf)
}