diff --git a/pkg/cfg/cfg_test.go b/pkg/cfg/cfg_test.go index b0de7e4309..38a283bc5f 100644 --- a/pkg/cfg/cfg_test.go +++ b/pkg/cfg/cfg_test.go @@ -41,3 +41,25 @@ tls: }, }, data) } + +func TestParseWithInvalidYAML(t *testing.T) { + yamlSource := dYAML([]byte(` +servers: + ports: 2000 + timeoutz: 60h +tls: + keey: YAML +`)) + + fs := flag.NewFlagSet(t.Name(), flag.PanicOnError) + flagSource := dFlags(fs, []string{"-verbose", "-server.port=21"}) + + data := Data{} + err := dParse(&data, + dDefaults(fs), + yamlSource, + flagSource, + ) + require.Error(t, err) + require.Equal(t, err.Error(), "yaml: unmarshal errors:\n line 2: field servers not found in type cfg.Data\n line 6: field keey not found in type cfg.TLS") +} diff --git a/pkg/cfg/files.go b/pkg/cfg/files.go index 4c6d2b67c8..c5ef8bbadb 100644 --- a/pkg/cfg/files.go +++ b/pkg/cfg/files.go @@ -55,7 +55,7 @@ func YAML(f *string) Source { // dYAML returns a YAML source and allows dependency injection func dYAML(y []byte) Source { return func(dst interface{}) error { - return yaml.Unmarshal(y, dst) + return yaml.UnmarshalStrict(y, dst) } }