Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

WireMockContainer

A WireMock server container for stubbing HTTP dependencies in integration tests. There is no first-class in-process WireMock story for Rust integration tests, so this module fills a real gap.

Default image: floats to wiremock/wiremock:latest — this module previously pinned wiremock/wiremock:3.13.2. Guest port: 8080 Expected repository: wiremock/wiremock

MethodOnEffect
WireMockContainer::new()builderFloating default image.
WireMockContainer::with_image(image)builderCaller-chosen image, kept verbatim.
.start()builder → Result<WireMockGuard>Checks the image’s repository, then boots the container.
.base_url()guardThe stub server’s base URI — mount stubbed paths under this.
.admin_url()guardThe /__admin management API’s base URI (stub CRUD, request journal, health).
.stop()guardStops and removes the container, releases its port.

Compatibility checking

with_image takes impl Into<ImageName> and keeps the image verbatim. start() then checks that image’s repository (registry host, tag, and digest stripped) against wiremock/wiremock before any backend is resolved or any sandbox is created, which keeps the constructors infallible like every other module’s. A mismatch returns RightsizeError::IncompatibleImage; ImageName::parse(image) .as_compatible_substitute_for("wiremock/wiremock") is the escape hatch for a verified drop-in replacement from another registry. new() goes through this same check against its own floating reference, so it can never fail in practice.

Readiness — verified against a real 3.13.2 boot

WireMock 3.x ships a dedicated /__admin/health endpoint (unlike some older 2.x builds, where /__admin/mappings was the only reliable 200). Verified directly against a real container:

$ curl http://127.0.0.1:<port>/__admin/health
{"status":"healthy","message":"Wiremock is ok","version":"3.13.2","uptimeInSeconds":9,...}

so this module waits on that endpoint rather than falling back to /__admin/mappings.

No with_memory_limit override was needed — the JVM boots comfortably on msb’s default ~450M microVM RAM (observed ~5.5s IT round-trip on msb; a small embedded-Jetty app, not a JVM-heavy cluster like Pinot).

Complete example

use rightsize_modules::WireMockContainer;

const STUB: &str = r#"{"request":{"method":"GET","urlPath":"/hello"},
                        "response":{"status":200,"body":"world"}}"#;

#[tokio::test]
async fn stub_mapping_round_trips() -> Result<(), Box<dyn std::error::Error>> {
    let guard = WireMockContainer::new().start().await?;

    let agent = ureq::Agent::new_with_defaults();
    agent
        .post(format!("{}/mappings", guard.admin_url()))
        .header("Content-Type", "application/json")
        .send(STUB)?;

    let mut get = agent.get(format!("{}/hello", guard.base_url())).call()?;
    let body = get.body_mut().read_to_string()?;
    assert_eq!(body, "world");

    guard.stop().await?;
    Ok(())
}

Backend notes

No memory-limit override is needed on either backend — see Readiness above.