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

Ability to offload large payloads with dynamic_response scripts #310

Open
gautaz opened this issue Oct 24, 2024 · 2 comments
Open

Ability to offload large payloads with dynamic_response scripts #310

gautaz opened this issue Oct 24, 2024 · 2 comments
Labels
feature-request New feature or request

Comments

@gautaz
Copy link

gautaz commented Oct 24, 2024

Hello,

First things first, smocker is dead simple to start with, keep up the good work!

Lately, I wanted to avoid putting a large piece of JSON directly in a mock definition so I tried to offload it to another file and read it from a Lua's script this way (I am not fluent in Lua by the way):

- request:
    method: GET
    path: /data/666
  dynamic_response:
    engine: lua
    script: >
      local io = require("io")
      local file = io.open("/data/666.json", "rb")
      if not file then return nil end
      local content = file:read "*a"
      file:close()
      return {
        body = content,
        headers = {
          ["Content-Type"] = {"application/json"}
        }
      }

But this fails because it cannot find io (whether I put a require or not).

At first I was wondering if GopherLua even supported file operations but this issue seems to confirm that this is the case.

May anyone shed some light on this particular point?

@Thiht
Copy link
Collaborator

Thiht commented Nov 11, 2024

Hi!
I explicitly disabled the io package, because allowing it would make Smocker's behaviour less predictable: the only way to define mocks is using the API, you can't use files already present on the disk.

There's a real use-case for large files and binary files though, and I'm thinking of a way to allow multipart mock declarations in the future to allow it. In the case of the Lua engine, the files would be injected directly into the Lua context so the io module still wouldn't be needed.

@Thiht Thiht added the feature-request New feature or request label Nov 11, 2024
@gautaz
Copy link
Author

gautaz commented Nov 11, 2024

Hello @Thiht,

Thanks for the details, I totally understand the "less predictable" argument.
Is there any other issue tracing this need so we might close this one in favor of and add a link to the right issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Development

No branches or pull requests

2 participants