Skip to content

Commit

Permalink
Fix a nil pointer deference in bundle.ValuesOrDefaults when there are…
Browse files Browse the repository at this point in the history
… no parameters defined in the bundle (#50)

Signed-off-by: Jean-Christophe Sirot <[email protected]>
  • Loading branch information
jcsirot authored and jeremyrickard committed Jun 25, 2019
1 parent 8507768 commit 5ca8550
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ type Action struct {

// ValuesOrDefaults returns parameter values or the default parameter values
func ValuesOrDefaults(vals map[string]interface{}, b *Bundle) (map[string]interface{}, error) {
res := map[string]interface{}{}

if b.Parameters == nil {
return res, nil
}

requiredMap := map[string]struct{}{}
for _, key := range b.Parameters.Required {
requiredMap[key] = struct{}{}
}
res := map[string]interface{}{}

for name, def := range b.Parameters.Fields {
s, ok := b.Definitions[def.Definition]
Expand Down
9 changes: 9 additions & 0 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ func TestValuesOrDefaults(t *testing.T) {
is.Error(err)
}

func TestValuesOrDefaults_NoParameter(t *testing.T) {
is := assert.New(t)
vals := map[string]interface{}{}
b := &Bundle{}
vod, err := ValuesOrDefaults(vals, b)
is.NoError(err)
is.Len(vod, 0)
}

func TestValuesOrDefaults_Required(t *testing.T) {
is := assert.New(t)
vals := map[string]interface{}{
Expand Down

0 comments on commit 5ca8550

Please sign in to comment.