(t *testing.T)
| 1234 | } |
| 1235 | |
| 1236 | func TestCustomParserBasicType(t *testing.T) { |
| 1237 | type ConstT int32 |
| 1238 | |
| 1239 | type config struct { |
| 1240 | Const ConstT `env:"CONST_"` |
| 1241 | } |
| 1242 | |
| 1243 | exp := ConstT(123) |
| 1244 | t.Setenv("CONST_", fmt.Sprintf("%d", exp)) |
| 1245 | |
| 1246 | customParserFunc := func(v string) (interface{}, error) { |
| 1247 | i, err := strconv.Atoi(v) |
| 1248 | if err != nil { |
| 1249 | return nil, err |
| 1250 | } |
| 1251 | r := ConstT(i) |
| 1252 | return r, nil |
| 1253 | } |
| 1254 | |
| 1255 | cfg := &config{} |
| 1256 | err := ParseWithOptions(cfg, Options{FuncMap: map[reflect.Type]ParserFunc{ |
| 1257 | reflect.TypeOf(ConstT(0)): customParserFunc, |
| 1258 | }}) |
| 1259 | |
| 1260 | isNoErr(t, err) |
| 1261 | isEqual(t, exp, cfg.Const) |
| 1262 | } |
| 1263 | |
| 1264 | func TestCustomParserUint64Alias(t *testing.T) { |
| 1265 | type T uint64 |
nothing calls this directly
no test coverage detected