Chapter 20¾: jev-http/tests — the whole client, over real TLS
One file, mock.rs: an integration test. Cargo builds each file in
a crate's tests/ folder as a separate program that can use only the
crate's public API, the way an outside caller would. (The nearest JavaScript
equivalent is an end-to-end test that imports the package by name rather
than reaching into its source.)
Every test starts jev_mock::MockJev on loopback, points a Jev at it
with Endpoint::parse(&mock.endpoint()).trusting(mock.ca_file()), and gives
it a ledger in a fresh temp directory. Nothing reaches the real API and
nothing touches the real ledger.
flowchart LR
T["test"] --> J["Jev::ask"]
J --> L[("sandbox ledger")]
J -->|"HTTP/2 over TLS, throwaway CA"| M["MockJev on 127.0.0.1"]
M -->|"Reply from the test's closure"| J
| Test | Shows |
|---|---|
answers_over_one_kept_connection_and_books_the_cost | Three asks, three requests, one TLS connection; every hold settled. |
the_ledger_refuses_before_anything_is_sent | With a bucket of one, the second ask is Failure::Throttled and the mock sees one request. |
out_of_credit_stops_every_later_ask | A 402 is OutOfCredit after one attempt, the next ask is Failure::Budget without a request, and the refused hold was released. |
a_plain_http_endpoint_is_refused | Endpoint::parse refuses http://. |
Try it
cargo test -p jev-http --test mock
For the people who maintain it
In this folder
| File | What |
|---|---|
| mock.rs | The four tests above, and the client and one_noul helpers. |
| CLAUDE.md | Invariants for agents. |
← Previous: Chapter 20½: inside jev-http/src · Up: jev-http · Next: Chapter 21: jev-mock →