Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to refer to files in mock definitions #161

Closed
x80486 opened this issue Sep 26, 2020 · 2 comments
Closed

Allow to refer to files in mock definitions #161

x80486 opened this issue Sep 26, 2020 · 2 comments

Comments

@x80486
Copy link

x80486 commented Sep 26, 2020

I'm working with ancient APIs these days. The responses are JSON or XML files around 3,000 (even more) lines length.

I would like to use Smocker at the new work place, but so far I haven't found a way to do something like this with Smocker:

- request:
    method: GET
    path: /hello/world
  response:
    headers:
      Content-Type: application/json
    body: file:/path/to/hello_world_response.json

I'm aware this not even valid YAML, but the file:/path/to/hello_world_response.json is just an example of what I'm trying to do, which is only to refer to a file with the content of the body, instead of putting the gigantic response there. If that's impossible to do these days, it would be nice to have a declarative way to implement such things in the YAML configuration file — probably with a fixed location for these kind of files.

Moreover, those are usually templates, because there is always something that needs to be changed before sending them back to the user-agents.

@x80486
Copy link
Author

x80486 commented Sep 27, 2020

Basically, something like this: https://cloud.spring.io/spring-cloud-contract/reference/html/project-features.html#features-wiremock-using-files ...for WireMock.

Instead of body, could be bodyFile, or bodyFromFile, etc.

@Thiht
Copy link
Collaborator

Thiht commented Sep 28, 2020

We also deal with very big payloads, and we usually just put them in the body. The mock file ends up big, but Smocker handles it just fine :)

Sometimes when we don't want to deal with very big mocks we have 2 solutions:

  1. write the whole body on a single line. If the mock is not intended to be modified or read, it's ok
  2. remove the useless parts from the body, and keep only the keys we use (whether it's JSON or XML)

But keep in mind, a mock file with a very big body should not be an issue for Smocker.


We don't really want to implement a reference to a file for 2 reasons:

  1. we want the mocks to be self contained as much as possible. It's easier to maintain, to understand, and it helps us keep Smocker's code relatively simple
  2. referencing an external file has its issues: where does the file come from? is it already loaded on Smocker via the persistence folder? is it loaded via another endpoint? this is not trivial to specify nor to implement, so I'd rather not implement something like this.

Is that ok for you?

@x80486 x80486 closed this as completed Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants