(t *testing.T)
| 1294 | } |
| 1295 | |
| 1296 | func TestTypeCustomParserBasicInvalid(t *testing.T) { |
| 1297 | type ConstT int32 |
| 1298 | |
| 1299 | type config struct { |
| 1300 | Const ConstT `env:"CONST_"` |
| 1301 | } |
| 1302 | |
| 1303 | t.Setenv("CONST_", "foobar") |
| 1304 | |
| 1305 | customParserFunc := func(_ string) (interface{}, error) { |
| 1306 | return nil, errors.New("random error") |
| 1307 | } |
| 1308 | |
| 1309 | cfg := &config{} |
| 1310 | err := ParseWithOptions(cfg, Options{FuncMap: map[reflect.Type]ParserFunc{ |
| 1311 | reflect.TypeOf(ConstT(0)): customParserFunc, |
| 1312 | }}) |
| 1313 | |
| 1314 | isEqual(t, cfg.Const, ConstT(0)) |
| 1315 | isErrorWithMessage(t, err, `env: parse error on field "Const" of type "env.ConstT": random error`) |
| 1316 | isTrue(t, errors.Is(err, ParseError{})) |
| 1317 | } |
| 1318 | |
| 1319 | func TestCustomParserNotCalledForNonAlias(t *testing.T) { |
| 1320 | type T uint64 |
nothing calls this directly
no test coverage detected