Skip to content

Commit

Permalink
Merge pull request #19 from senseyeio/bugfix/behaviors_unmarshal
Browse files Browse the repository at this point in the history
Fixes issue with unmarshalling a Response with Behavior
  • Loading branch information
dtm authored Feb 21, 2023
2 parents 95b12e1 + 94ef5af commit aa38c5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,13 @@ func (r *Response) UnmarshalJSON(b []byte) error {
// Handle and delete behaviors from the DTO map before we check the
// type so that we can enforce only one type exists in the map.
if b, ok := dto[keyBehaviors]; ok {
err = json.Unmarshal(b, r.Behaviors)
behaviors := new(Behaviors)
err = json.Unmarshal(b, behaviors)
if err != nil {
return err
}
delete(dto, keyBehaviors)
r.Behaviors = behaviors
}

for key, b := range dto {
Expand Down
6 changes: 6 additions & 0 deletions dto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ func TestImposter_UnmarshalJSON(t *testing.T) {
},
"body": `{"response":true}`,
},
"_behaviors": map[string]interface{}{
"wait": 500,
},
},
},
},
Expand Down Expand Up @@ -702,6 +705,9 @@ func TestImposter_UnmarshalJSON(t *testing.T) {
},
Body: `{"response":true}`,
},
Behaviors: &mbgo.Behaviors{
Wait: 500,
},
},
},
},
Expand Down

0 comments on commit aa38c5e

Please sign in to comment.