Skip to content

Commit

Permalink
Merge pull request #25 from StephanHCB/fix-playback
Browse files Browse the repository at this point in the history
fix(RELTEC-11372): do not marshal strings during playback
  • Loading branch information
StephanHCB committed Aug 22, 2023
2 parents 1cf4096 + 4c1e7a2 commit 177d92f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions implementation/playback/playback.go
Expand Up @@ -93,16 +93,28 @@ func (c *PlaybackImpl) Perform(ctx context.Context, method string, requestUrl st
response.Status = recording.ParsedResponse.Status
response.Time = c.Now()

// cannot just assign the body, need to re-parse into the existing pointer - using a json round trip
bodyJsonBytes, err := json.Marshal(recording.ParsedResponse.Body)
if err != nil {
return err
}

switch response.Body.(type) {
case **[]byte:
*(response.Body.(**[]byte)) = &bodyJsonBytes
asString, ok := recording.ParsedResponse.Body.(string)
if ok {
asBytes := []byte(asString)
*(response.Body.(**[]byte)) = &asBytes
} else {
// For backwards compatibility with existing recordings we fall back to the previous logic.
// This is because in these old recordings the body is stored as a json object instead of a string.
// This is not compatible with the changes introduced in 0.7.2
bodyJsonBytes, err := json.Marshal(recording.ParsedResponse.Body)
if err != nil {
return err
}
*(response.Body.(**[]byte)) = &bodyJsonBytes
}
default:
// cannot just assign the body, need to re-parse into the existing pointer - using a json round trip
bodyJsonBytes, err := json.Marshal(recording.ParsedResponse.Body)
if err != nil {
return err
}
err = json.Unmarshal(bodyJsonBytes, response.Body)
if err != nil {
return err
Expand Down

0 comments on commit 177d92f

Please sign in to comment.