A mock server simulates an external service during a test. Pointing the application at a local endpoint preserves the real HTTP client code while allowing the test to exercise predefined success and error responses. section 11.1.3
For a profanity check, create a Rust library with `cargo new --lib mock-server` and add it as a local dependency. The server should start at a specified address and port, expose the third-party route, accept the same parameters, and return preset JSON responses. Configure the API URL so the test can target localhost instead of the real service. section 11.1.3
Shut the server down after the test. A Tokio oneshot channel provides a way for the test to signal shutdown. section 11.1.3
Figure 11.3 A oneshot channel to send exactly one message can be used to trigger a shutdown from the receiver side of the message.
The diagram illustrates how a oneshot message triggers server shutdown. section 11.1.3
