Skip to content

Commit

Permalink
Strict config
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jul 14, 2018
1 parent febd035 commit a1c02e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func LoadConfig(filename string) (*Config, error) {
return nil, errors.Wrap(err, "unable to read config")
}

if err := yaml.Unmarshal(b, &config); err != nil {
if err := yaml.UnmarshalStrict(b, &config); err != nil {
return nil, errors.Wrap(err, "unable to parse config")
}

Expand Down
5 changes: 5 additions & 0 deletions codegen/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func TestLoadConfig(t *testing.T) {
_, err := LoadConfig("testdata/cfg/malformedconfig.yml")
require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `asdf` into codegen.Config")
})

t.Run("unknown keys", func(t *testing.T) {
_, err := LoadConfig("testdata/cfg/unknownkeys.yml")
require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 2: field unknown not found in type codegen.Config")
})
}

func TestLoadDefaultConfig(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions codegen/testdata/cfg/unknownkeys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: outer
unknown: foo

0 comments on commit a1c02e7

Please sign in to comment.