Skip to content

Conversation

Powerrr
Copy link

@Powerrr Powerrr commented May 22, 2023

Check that body is not nil before serializing it to json.
This fixes an issue where a mock like this

- request:
    method: GET
    path: /foo
  dynamic_response:
    engine: go_template_json
    script: |
      {
        "status": 302,
        "headers": {"Location": "https://example.org/"}
      }

returns literal null as a response body instead of an empty body.

PS: to be honest, I think this entire if block is redundant because it makes the behavior inconsistent between dynamic-response mocks and static-response mocks: in static-response mocks we only allow strings as body and don't convert arbitrary objects into strings.

@gwleclerc
Copy link
Collaborator

This if has been added because without it, the user should escape all the quotation marks when he wants to return a json object in a go_template script which makes the mocks more difficult to read and write.

@gwleclerc gwleclerc changed the base branch from master to fix/go_template_json October 4, 2023 19:12
@gwleclerc gwleclerc merged commit 7f95744 into smocker-dev:fix/go_template_json Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants