mockforge_test/lib.rs
1//! # MockForge Test Utilities
2//!
3//! Test utilities for MockForge to simplify integration with test frameworks like Playwright and Vitest.
4//!
5//! ## Features
6//!
7//! - **Easy Server Spawning**: Start and stop MockForge servers programmatically
8//! - **Health Checks**: Wait for server readiness with configurable timeouts
9//! - **Scenario Management**: Switch scenarios/workspaces per-test
10//! - **Process Management**: Automatic cleanup of spawned processes
11//! - **Profile Support**: Run with different MockForge profiles
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use mockforge_test::{MockForgeServer, ServerConfig};
17//!
18//! #[tokio::test]
19//! async fn test_with_mockforge() {
20//! // Start MockForge server
21//! let server = MockForgeServer::builder()
22//! .http_port(3000)
23//! .build()
24//! .await
25//! .expect("Failed to start server");
26//!
27//! // Server is ready - run your tests
28//! let response = reqwest::get("http://localhost:3000/health")
29//! .await
30//! .expect("Failed to get health");
31//!
32//! assert!(response.status().is_success());
33//!
34//! // Server automatically stops when dropped
35//! }
36//! ```
37//!
38//! ## Scenario Switching
39//!
40//! ```rust,no_run
41//! use mockforge_test::MockForgeServer;
42//!
43//! #[tokio::test]
44//! async fn test_scenario_switching() {
45//! let server = MockForgeServer::builder()
46//! .http_port(3000)
47//! .build()
48//! .await
49//! .expect("Failed to start server");
50//!
51//! // Switch to a different scenario
52//! server.scenario("user-auth-success")
53//! .await
54//! .expect("Failed to switch scenario");
55//!
56//! // Test with the new scenario
57//! // ...
58//! }
59//! ```
60
61pub mod config;
62pub mod error;
63pub mod fixtures;
64pub mod health;
65mod port_reservation;
66pub mod process;
67pub mod scenario;
68pub mod server;
69
70pub use config::{ServerConfig, ServerConfigBuilder};
71pub use error::{Error, Result};
72pub use fixtures::{
73 minimal_openapi_spec, openapi_spec_crud, openapi_spec_with_get, write_spec_to, write_temp_spec,
74};
75pub use health::{HealthCheck, HealthStatus};
76pub use scenario::ScenarioManager;
77pub use server::MockForgeServer;
78
79/// Re-export commonly used types
80pub use reqwest;
81pub use tokio;
82
83#[cfg(test)]
84mod tests {
85 use super::*;
86
87 #[test]
88 fn test_config_builder() {
89 let config = ServerConfig::builder().http_port(3000).admin_port(3001).build();
90
91 assert_eq!(config.http_port, 3000);
92 assert_eq!(config.admin_port, Some(3001));
93 }
94}