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

[feature request] Provide a way to mock backend responses when using viceroy as a test runner #442

Open
tedmielczarek-fastly opened this issue Nov 14, 2024 · 2 comments

Comments

@tedmielczarek-fastly
Copy link

When using viceroy as a test runner it would be helpful if there were a way to mock backend responses. The motivation for this is twofold:

  1. Tests that make external network requests are inherently flaky due to transient network issues. It would be much better for reliability if backend requests in tests did not have to make an external request.
  2. Writing unit-style tests is much easier if you can mock external dependencies. If your test is making external requests it's an integration test whether you like it or not. While integration tests are valuable, using mocks for unit tests allows writing tests for edge cases such as handling specific errors which are much more difficult to test against a real external service.

I don't know the viceroy codebase well so I can't offer useful implementation suggestions, but from a user's perspective I can imagine a few ideas of solutions that would be useful:

  • A hostcall that allows mocking requests for a backend, either by providing a handler routine in the wasm module or by directly providing a response that should be used.
  • A commandline argument to provide a handler routine in the wasm module to be used to handle requests for a specific backend, e.g. --mock-backend=my-backend=some_function_name.

Either of these would provide enough functionality to address the two points in the motivation list above.

@dgryski
Copy link
Member

dgryski commented Nov 14, 2024

Depending on the level of configurability needed, we could even do something like embedding https://github.com/facebook/starlark-rust to allow viceroy "scripts" to handle creating responses.

@tedmielczarek-fastly
Copy link
Author

For the purposes of mocking backends for tests I would personally prefer a solution that allows using a handler function alongside the existing code in the module.

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

2 participants