Skip to main content

Crate hafas_sim

Crate hafas_sim 

Source
Expand description

Fake HAFAS ReST server on loopback that serves trimmed RMV responses, for tests.

The answers come from fixtures/, one set per dialect version: 2.39 below /hapi/ and 2.52 below /hapi/latest/, as on the RMV server. Injections change them, to produce cancellations, delays and errors on demand. Every request is recorded, so tests can check what was sent, and that nothing was sent.

The sim accepts only ACCESS_ID. It answers a request without a key and one with another key with the errors of the RMV server, but it never repeats the key it was sent.

use hafas_sim::{Failure, Injection, Sim};

let sim = Sim::start().await;
sim.inject(Injection::Fail(Failure::status(503).times(1)));
// point the client under test at sim.base_url() or sim.latest_url()
assert_eq!(sim.requests().len(), 0);

Structs§

Failure
An error answer, for Injection::Fail.
Recorded
A request the sim received. A key other than ACCESS_ID is recorded as REDACTED.
Sim
A running sim. It stops when dropped.

Enums§

Endpoint
The services the sim serves.
Injection
A change to the answers of the sim. Injections stay until Sim::clear.
Version
A dialect version of the API, with its own fixtures.

Constants§

ACCESS_ID
The access key the sim accepts.
CANCELLED_JOURNEY
The journey of journeyDetail-cancelled.json (2.39): the tram 17 at 09:10, cancelled. journeyDetail answers with that fixture for it.
DEPARTURE_JOURNEY
The first departure of departureBoard.json (2.39): the S2 at 08:40.
REDACTED
What a recorded request holds instead of a key that is not ACCESS_ID.

Functions§

fixture
The fixture name of version, like trip.json or errors/auth.xml.