-
-
Notifications
You must be signed in to change notification settings - Fork 271
Open
Description
// use github.com/caarlos0/env/v11 v11.3.1
func TestCustomParserWIthDefault(t *testing.T) {
type foo struct {
name string
}
type bar struct {
Name string `env:"OTHER_CUSTOM"`
Foo *foo `env:"BLAH_CUSTOM"`
}
type config struct {
Var foo `env:"VAR_CUSTOM"`
Foo *foo `env:"BLAH_CUSTOM"`
Other *bar
}
t.Setenv("VAR_CUSTOM", "test")
t.Setenv("OTHER_CUSTOM", "test2")
t.Setenv("BLAH_CUSTOM", "test3")
runtest := func(t *testing.T) {
t.Helper()
cfg := &config{
Var: foo{"var"},
Foo: &foo{"foo"},
Other: &bar{
Name: "name",
Foo: &foo{"foo"},
},
}
err := ParseWithOptions(cfg, Options{FuncMap: map[reflect.Type]ParserFunc{
reflect.TypeOf(foo{}): func(v string) (interface{}, error) {
return foo{name: v}, nil
},
}})
isNoErr(t, err)
expect := &config{
Var: foo{"test"},
Foo: &foo{"test3"},
Other: &bar{
Name: "test2",
Foo: &foo{"test3"},
},
}
assert.Equal(t, expect, cfg)
}
for i := 0; i < 10; i++ {
t.Run(fmt.Sprintf("%d", i), runtest)
}
}
this test is failed
Diff:
--- Expected
+++ Actual
@@ -5,3 +5,3 @@
Foo: (*env.foo)({
- name: (string) (len=5) "test3"
+ name: (string) (len=3) "foo"
}),
@@ -10,3 +10,3 @@
Foo: (*env.foo)({
- name: (string) (len=5) "test3"
+ name: (string) (len=3) "foo"
})
this patch serg2014@931c721
resolve problem
Metadata
Metadata
Assignees
Labels
No labels