1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! HTTP Endpoint Server Harness
//!
//! A test harness for mocking HTTP endpoints with predefined responses.
//! The server automatically shuts down once all handlers have been called.
//!
//! # Example
//!
//! ```rust,no_run
//! use http_endpoint_server_harness::prelude::*;
//! use std::net::SocketAddr;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), HarnessError> {
//! // Define a fixed address for the server
//! let addr: SocketAddr = "127.0.0.1:3000".parse().unwrap();
//!
//! // Spawn a task to make HTTP requests
//! let requests_task = tokio::spawn(async move {
//! // Wait for server to be ready (in real code, add proper retry logic)
//! tokio::time::sleep(std::time::Duration::from_millis(100)).await;
//!
//! let client = reqwest::Client::new();
//! let _response = client
//! .get(format!("http://{}/api/users", addr))
//! .send()
//! .await
//! .unwrap();
//! });
//!
//! // Build and execute a scenario using the builder pattern
//! let collected = ScenarioBuilder::new()
//! .server(Axum::bind(addr))
//! .collector(DefaultCollector::new())
//! .endpoint(
//! Endpoint::new("/api/users", Method::Get)
//! .with_handler(Handler::from_json(&json!({"id": 1})))
//! )
//! .build()
//! .execute()
//! .await?;
//!
//! requests_task.await.unwrap();
//!
//! // Server has automatically shut down, collected contains all requests
//! for req in &collected {
//! println!("Received: {} {}", req.method, req.path);
//! }
//!
//! Ok(())
//! }
//! ```
pub use HarnessError;
pub use Axum;
/// Default collector implementation that collects requests into a Vec
/// Prelude module for convenient imports