Crate lava_api_mock
source · [−]Expand description
This crate provides a set of types for constructing mock servers providing the LAVA REST API with generated data.
Overview
The main types in a Lava database have types in this crate:
AliasArchitectureBitWidthCoreDeviceDeviceTypeGroupJobProcessorFamilyTagTestCaseTestSetTestSuiteUserWorker
There is a container type State which implements
Context from the
persian-rug crate. All types are
GeneratableWithPersianRug
and BuildableWithPersianRug
which are from the boulder crate.
LavaMock
Most users will want to base their tests around LavaMock,
which is a django-query derived server, which
provides all of the v0.2 query REST endpoints of a standard Lava
server. See the documentation for details of its limitations. The
data it serves comes from a SharedState (a synchronised
wrapper over a State) which can both be populated with default
data as a starting point, and also updated on the fly to simulate
whatever update pattern is desired.
Example:
use futures::stream::TryStreamExt;
use lava_api_mock::{LavaMock, PaginationLimits, PopulationParams, SharedState};
use lava_api::Lava;
// Make the mock server
let limits = PaginationLimits::new();
let population = PopulationParams::new();
let mock = LavaMock::new(SharedState::new_populated(population), limits).await;
// Make the Lava client for reading back data from the server
let lava = Lava::new(&mock.uri(), None).expect("failed to make lava client");
// Read back the devices using the Lava client
let mut ld = lava.devices();
while let Some(device) = ld
.try_next()
.await
.expect("failed to read devices from server")
{
println!("Got device {:?}", device);
}Structs
SharedState.LavaMock instance.StateState for shared access.