3 releases

0.1.2 Jan 13, 2024
0.1.1 Jan 13, 2023
0.1.0 Oct 31, 2022

#536 in Testing

31 downloads per month
Used in lava-api

MIT/Apache

120KB
2.5K SLoC

Rust lava api crate

This crate provides access to the LAVA REST API


lib.rs:

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:

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);
}

Dependencies

~18–27MB
~398K SLoC