Skip to main content

render_common_module

Function render_common_module 

Source
pub fn render_common_module() -> String
Expand description

Generate the tests/common.rs module for Rust e2e tests.

The module spawns the standalone mock-server binary once per test process and exposes it via mock_server_url() which reads the MOCK_SERVER_URL env var. This allows tests that use mock_url arguments to access the server dynamically without panicking on unset env vars.

The module:

  • Spawns target/release/mock-server with the fixtures directory as an argument
  • Reads stdout lines looking for MOCK_SERVER_URL=http://... and MOCK_SERVERS={...}
  • Sets environment variables: MOCK_SERVER_URL and MOCK_SERVER_<FIXTURE_ID> for each entry
  • Drains remaining stdout in a background thread to prevent blocking
  • Uses OnceLock to ensure the server is spawned exactly once