MCPcopy
hub / github.com/pelletier/go-toml / TestUnmarshalStringInvalidStructField

Function TestUnmarshalStringInvalidStructField

unmarshaler_test.go:2591–2622  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2589}
2590
2591func TestUnmarshalStringInvalidStructField(t *testing.T) {
2592 type Server struct {
2593 Path string
2594 Port int
2595 }
2596
2597 type Cfg struct {
2598 Server Server
2599 }
2600
2601 var cfg Cfg
2602
2603 data := `[server]
2604path = "/my/path"
2605port = "bad"
2606`
2607
2608 file := strings.NewReader(data)
2609 err := toml.NewDecoder(file).Decode(&cfg)
2610 assert.Error(t, err)
2611
2612 var x *toml.DecodeError
2613 assert.True(t, errors.As(err, &x))
2614 assert.Equal(t, "toml: cannot decode TOML string into struct field toml_test.Server.Port of type int", x.Error())
2615 expected := `1| [server]
26162| path = "/my/path"
26173| port = "bad"
2618 | ~~~~~ cannot decode TOML string into struct field toml_test.Server.Port of type int`
2619
2620 assert.Equal(t, expected, x.String())
2621 assert.Equal(t, toml.Key{"server", "port"}, x.Key())
2622}
2623
2624func TestUnmarshalIntegerInvalidStructField(t *testing.T) {
2625 type Server struct {

Callers

nothing calls this directly

Calls 7

ErrorMethod · 0.95
StringMethod · 0.95
KeyMethod · 0.95
ErrorFunction · 0.92
TrueFunction · 0.92
EqualFunction · 0.92
DecodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…