Skip to content

Commit

Permalink
Make yaml.Unmarshal strict and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ronensc committed Jul 28, 2022
1 parent db266db commit 90e775f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/api/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func TestDuration_MarshalYAML(t *testing.T) {
func TestDuration_UnmarshalYAML(t *testing.T) {
expectedMsg := testMessage{Elapsed: Duration{2 * time.Hour}}
var actualMsg testMessage
require.NoError(t, yaml.Unmarshal([]byte("elapsed: 2h\n"), &actualMsg))
require.NoError(t, yaml.UnmarshalStrict([]byte("elapsed: 2h\n"), &actualMsg))
require.Equal(t, expectedMsg, actualMsg)
}
4 changes: 2 additions & 2 deletions pkg/confgen/confgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ func (cg *ConfGen) parseFile(fileName string) error {
log.Debugf("ioutil.ReadFile err: %v ", err)
return err
}
err = yaml.Unmarshal(yamlFile, &defFile)
err = yaml.UnmarshalStrict(yamlFile, &defFile)
if err != nil {
log.Debugf("yaml.Unmarshal err: %v ", err)
log.Debugf("yaml.UnmarshalStrict err: %v ", err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/confgen/confgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ details:
test details
usage:
test usage
labels:
tags:
- test
- label
transform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/confgen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (cg *ConfGen) ParseConfigFile(fileName string) (*Config, error) {
log.Debugf("ioutil.ReadFile err: %v ", err)
return nil, err
}
err = yaml.Unmarshal(yamlFile, &config)
err = yaml.UnmarshalStrict(yamlFile, &config)
if err != nil {
log.Debugf("Unmarshal err: %v ", err)
return nil, err
Expand Down

0 comments on commit 90e775f

Please sign in to comment.