Skip to content

Commit

Permalink
Merge pull request #1511 from mesg-foundation/feature/null-parameter-…
Browse files Browse the repository at this point in the history
…value

Fix bug when Value_NullValue is not taking into account
  • Loading branch information
Nicolas Mahé authored Nov 19, 2019
2 parents 62265cc + 64b0e79 commit 630d01a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions service/service_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func validateServiceParameters(parameters []*Service_Parameter, data *types.Stru
errs = append(errs, err)
}
}

return errs.ErrorOrNil()
}

// Validate checks if service parameter hash proper types for arrays and objects.
func (p *Service_Parameter) Validate(value *types.Value) error {
if value == nil {
_, isNull := value.GetKind().(*types.Value_NullValue)
if value == nil || isNull {
if p.Optional {
return nil
}
Expand Down
18 changes: 18 additions & 0 deletions service/service_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ func TestValidate(t *testing.T) {
},
expecterr: true,
},
{
name: "optional null",
params: []*Service_Parameter{
{
Key: "key",
Type: "Object",
Optional: true,
},
},
data: &types.Struct{
Fields: map[string]*types.Value{
"key": {
Kind: &types.Value_NullValue{},
},
},
},
expecterr: false,
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit 630d01a

Please sign in to comment.