pub struct FixtureLoader { /* private fields */ }Expand description
Fixture data loader
Implementations§
Source§impl FixtureLoader
impl FixtureLoader
Sourcepub fn new() -> FixtureLoader
pub fn new() -> FixtureLoader
Create a new fixture loader
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
// Loader is ready to load fixturesSourcepub async fn load_from_json(
&self,
name: String,
json: &str,
) -> Result<(), FixtureError>
pub async fn load_from_json( &self, name: String, json: &str, ) -> Result<(), FixtureError>
Load fixture from JSON string
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
let json = r#"{"id": 1, "name": "Test"}"#;
loader.load_from_json("test".to_string(), json).await.unwrap();
assert!(loader.exists("test").await);Sourcepub async fn load<T>(&self, name: &str) -> Result<T, FixtureError>where
T: for<'de> Deserialize<'de>,
pub async fn load<T>(&self, name: &str) -> Result<T, FixtureError>where
T: for<'de> Deserialize<'de>,
Load fixture data
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
use serde::Deserialize;
#[derive(Deserialize)]
struct User {
id: i32,
name: String,
}
let loader = FixtureLoader::new();
let json = r#"{"id": 1, "name": "Alice"}"#;
loader.load_from_json("user".to_string(), json).await.unwrap();
let user: User = loader.load("user").await.unwrap();
assert_eq!(user.id, 1);
assert_eq!(user.name, "Alice");Sourcepub async fn get(&self, name: &str) -> Result<Value, FixtureError>
pub async fn get(&self, name: &str) -> Result<Value, FixtureError>
Get raw fixture value
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
let json = r#"{"status": "active"}"#;
loader.load_from_json("config".to_string(), json).await.unwrap();
let value = loader.get("config").await.unwrap();
assert!(value.is_object());Sourcepub async fn exists(&self, name: &str) -> bool
pub async fn exists(&self, name: &str) -> bool
Check if fixture exists
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
assert!(!loader.exists("missing").await);
loader.load_from_json("test".to_string(), "{}").await.unwrap();
assert!(loader.exists("test").await);Sourcepub async fn clear(&self)
pub async fn clear(&self)
Clear all fixtures
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
loader.load_from_json("test".to_string(), "{}").await.unwrap();
assert_eq!(loader.list().await.len(), 1);
loader.clear().await;
assert_eq!(loader.list().await.len(), 0);Sourcepub async fn list(&self) -> Vec<String>
pub async fn list(&self) -> Vec<String>
List all fixture names
§Examples
use reinhardt_testkit::fixtures::FixtureLoader;
let loader = FixtureLoader::new();
loader.load_from_json("test1".to_string(), "{}").await.unwrap();
loader.load_from_json("test2".to_string(), "{}").await.unwrap();
let names = loader.list().await;
assert_eq!(names.len(), 2);
assert!(names.contains(&"test1".to_string()));Trait Implementations§
Source§impl Default for FixtureLoader
impl Default for FixtureLoader
Source§fn default() -> FixtureLoader
fn default() -> FixtureLoader
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for FixtureLoader
impl !RefUnwindSafe for FixtureLoader
impl Send for FixtureLoader
impl Sync for FixtureLoader
impl Unpin for FixtureLoader
impl UnsafeUnpin for FixtureLoader
impl !UnwindSafe for FixtureLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().