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

Support relative paths for file.contents #149

Open
andyundso opened this issue Oct 20, 2023 · 0 comments
Open

Support relative paths for file.contents #149

andyundso opened this issue Oct 20, 2023 · 0 comments

Comments

@andyundso
Copy link

Hello!

We have a quite custom setup where we run integration tests for a Node application on Linux and Windows. We use mmock to mock out couple of outside systems. For a new operation, we do file downloads and therefore would like to use file.contents. Below is the configuration we use currently:

{
  "request": {
    "method": "GET",
    "path": "/api/v1/downloadBigFile/*"
  },
  "response": {
    "statusCode": 200,
    "headers": {
      "Content-Type": ["text/plain"]
    },
    "body": "{{file.contents(/config/test_file.txt)}}"
  }
}

This works on Linux, as we can guarantee that the file is present there. However, on Windows, specifically the Azure pipeline we have, we cannot use Linux containers and need to start mmock natively. The mmock configuration is checked into Git, which on Azure pipelines gets cloned to something like D:/a/1/s. Therefore, the current mmock configuration does not work.

I saw that the file.contents replacements uses io.ReadFile under the hood, which I think needs absolute paths to work. What would help for our scenario is if file.contents would support paths relative to the configuration file, e.g.:

{
  "request": {
    "method": "GET",
    "path": "/api/v1/downloadBigFile/*"
  },
  "response": {
    "statusCode": 200,
    "headers": {
      "Content-Type": ["text/plain"]
    },
    "body": "{{file.contents(test_file.txt)}}"
  }
}

so if we save this config file to /config/config.json, mmock would resolve the path for test_file.txt to /config/test_file.txt on Linux and D:/a/1/s/config/test_file.txt on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant