Expand description
Test utilities and fixtures for the Fluxion reactive streaming library.
This crate provides helper types, test data structures, and utilities for testing stream operators and async processing. It is designed for use in development and testing only, not for production code.
§Architecture
Fluxion maintains a clean separation between production and test code:
- Production: Use
FluxionStreamfor pure, functional stream operations - Testing: Use
futures::channel::mpsc::unboundedfor imperative test setup
This separation solves the conflict between consuming operations (stream extensions
that take self) and mutation operations (sending values via channels).
§Key Types
§Sequenced<T>
A wrapper type that adds temporal ordering to test values:
use fluxion_test_utils::Sequenced;
use fluxion_core::Timestamped;
let item = Sequenced::new(42); // Auto-assigned counter-based timestamp
assert_eq!(item.value, 42); // Access inner value via field§TestData and Variants
Enum types for creating diverse test scenarios:
use fluxion_test_utils::test_data::{TestData, person_alice, person_bob};
// Use pre-defined fixtures
let alice = person_alice();
let bob = person_bob();
// Create custom test data
match alice {
TestData::Person(p) => assert_eq!(p.name, "Alice"),
_ => panic!("Expected person"),
}§Test Fixtures
Pre-defined types for common test scenarios:
Person- Represents a person with id and nameAnimal- Represents an animal with id and speciesPlant- Represents a plant with id and name
§Examples
§Creating Ordered Test Values
use fluxion_test_utils::Sequenced;
use fluxion_core::{Timestamped, HasTimestamp};
// Create timestamped values with explicit ordering
let first = Sequenced::with_timestamp(100, 1);
let second = Sequenced::with_timestamp(200, 2);
let third = Sequenced::with_timestamp(300, 3);
// Verify ordering
assert!(first.timestamp() < second.timestamp());
assert!(second.timestamp() < third.timestamp());
// Access inner values
assert_eq!(first.value, 100);
assert_eq!(second.value, 200);
assert_eq!(third.value, 300);§Using Assertion Helpers
use fluxion_test_utils::assert_no_element_emitted;
use futures::stream;
let mut empty = stream::empty::<i32>();
assert_no_element_emitted(&mut empty, 10).await;§Module Organization
timestamped-Timestamped<T>wrapper and implementationstest_data- Enum variants for diverse test scenariosperson,animal,plant- Specific fixture typeshelpers- Assertion and utility functions
Re-exports§
pub use error_injection::ErrorInjectingStream;pub use helpers::assert_no_element_emitted;pub use helpers::assert_stream_ended;pub use helpers::test_channel;pub use helpers::test_channel_with_errors;pub use helpers::unwrap_all;pub use helpers::unwrap_stream;pub use helpers::unwrap_value;pub use sequenced::Sequenced;pub use test_data::DataVariant;pub use test_data::TestData;
Modules§
- animal
- error_
injection - Test utilities for error injection in streams.
- helpers
- person
- plant
- sequenced
- test_
data - test_
wrapper
Macros§
- with_
timeout - Macro to wrap test bodies with timeout to prevent hanging tests