lava_api_mock/
lib.rs

1//! This crate provides a set of types for constructing mock servers
2//! providing the [LAVA](https://docs.lavasoftware.org/lava/) REST API
3//! with generated data.
4//!
5//! # Overview
6//!
7//! The main types in a Lava database have types in this crate:
8//! - [`Alias`]
9//! - [`Architecture`]
10//! - [`BitWidth`]
11//! - [`Core`]
12//! - [`Device`]
13//! - [`DeviceType`]
14//! - [`Group`]
15//! - [`Job`]
16//! - [`ProcessorFamily`]
17//! - [`Tag`]
18//! - [`TestCase`]
19//! - [`TestSet`]
20//! - [`TestSuite`]
21//! - [`User`]
22//! - [`Worker`]
23//!
24//! There is a container type [`State`] which implements
25//! [`Context`](persian_rug::Context) from the
26//! [`persian-rug`](persian_rug) crate. All types are
27//! [`GeneratableWithPersianRug`](boulder::GeneratableWithPersianRug)
28//! and [`BuildableWithPersianRug`](boulder::BuildableWithPersianRug)
29//! which are from the [`boulder`] crate.
30//!
31//! # LavaMock
32//!
33//! Most users will want to base their tests around [`LavaMock`],
34//! which is a [`django-query`](django_query) derived server, which
35//! provides all of the v0.2 query REST endpoints of a standard Lava
36//! server. See the documentation for details of its limitations. The
37//! data it serves comes from a [`SharedState`] (a synchronised
38//! wrapper over a [`State`]) which can both be populated with default
39//! data as a starting point, and also updated on the fly to simulate
40//! whatever update pattern is desired.
41//!
42//! Example:
43//! ```rust
44//! use futures::stream::TryStreamExt;
45//! use lava_api_mock::{LavaMock, PaginationLimits, PopulationParams, SharedState};
46//! use lava_api::Lava;
47//!
48//! # tokio_test::block_on( async {
49//! // Make the mock server
50//! let limits = PaginationLimits::new();
51//! let population = PopulationParams::new();
52//! let mock = LavaMock::new(SharedState::new_populated(population), limits).await;
53//!
54//! // Make the Lava client for reading back data from the server
55//! let lava = Lava::new(&mock.uri(), None).expect("failed to make lava client");
56//!
57//! // Read back the devices using the Lava client
58//! let mut ld = lava.devices();
59//! while let Some(device) = ld
60//!     .try_next()
61//!     .await
62//!     .expect("failed to read devices from server")
63//! {
64//!     println!("Got device {:?}", device);
65//! }
66//! # });
67//! ```
68
69mod devices;
70mod devicetypes;
71mod jobs;
72mod junit;
73mod lava_mock;
74mod state;
75mod tags;
76mod testcases;
77mod users;
78mod workers;
79
80pub use devices::{Device, Health as DeviceHealth, State as DeviceState};
81pub use devicetypes::{Alias, Architecture, BitWidth, Core, DeviceType, ProcessorFamily};
82pub use jobs::Job;
83pub use jobs::{Health as JobHealth, State as JobState};
84pub use junit::{junit_endpoint, JunitEndpoint};
85pub use lava_mock::{LavaMock, PaginationLimits};
86pub use state::{PopulationParams, SharedState, State};
87pub use tags::Tag;
88pub use testcases::{Metadata, PassFail, TestCase, TestSet, TestSuite};
89pub use users::{Group, User};
90pub use workers::Worker;