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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//! Testing utilities for Armature framework.
//!
//! This crate provides comprehensive testing tools for Armature applications.
//!
//! ## Features
//!
//! - ๐งช **TestApp** - Integration test builder
//! - ๐ก **TestClient** - HTTP test client
//! - ๐ญ **MockService** - Service mocking
//! - ๐๏ธ **Spy** - Manual call recording (see [`Spy`] - it records what you tell
//! it to; it does not intercept calls to the value it wraps)
//! - โ
**Assertions** - Fluent test assertions
//! - ๐๏ธ **Integration Helpers** - Database setup/teardown
//! - ๐ณ **Docker Containers** - Docker-based testing
//! - ๐ **Load Testing** - Performance test utilities
//! - ๐ **Contract Testing** - Pact/consumer-driven contracts
//!
//! ## Quick Start
//!
//! ```no_run
//! use armature_testing::*;
//! use armature_core::{HttpRequest, HttpResponse, Error};
//!
//! # tokio_test::block_on(async {
//! // Create a test app
//! let app = TestAppBuilder::new()
//! .with_route("/hello", |_req| async {
//! Ok(HttpResponse::ok().with_body(b"Hello!".to_vec()))
//! })
//! .build();
//!
//! // Make test requests
//! let client = app.client();
//! let response = client.get("/hello").await;
//! assert_eq!(response.status(), Some(200));
//! assert_eq!(response.body_string(), Some("Hello!".to_string()));
//! # });
//! ```
//!
//! ## Testing Controllers
//!
//! ```no_run
//! use armature_testing::*;
//! use armature_core::{HttpRequest, HttpResponse, Error};
//!
//! # tokio_test::block_on(async {
//! let app = TestAppBuilder::new()
//! .with_route("/api/users", |_req| async {
//! Ok(HttpResponse::ok().with_json(&serde_json::json!({
//! "users": ["Alice", "Bob"]
//! }))?)
//! })
//! .build();
//!
//! let client = app.client();
//! let response = client.get("/api/users").await;
//! let json: serde_json::Value = response.body_json().unwrap();
//! assert_eq!(json["users"][0], "Alice");
//! # });
//! ```
//!
//! ## Mock Services
//!
//! ```
//! use armature_testing::MockService;
//!
//! // Create a mock service
//! let mock = MockService::<String>::new();
//! mock.record_call("get_user");
//!
//! // Verify calls
//! assert_eq!(mock.call_count(), 1);
//! assert!(mock.was_called("get_user"));
//! ```
//!
//! ## Assertions
//!
//! ```
//! use armature_testing::*;
//! use armature_core::HttpResponse;
//!
//! let response = HttpResponse::ok()
//! .with_header("Content-Type".to_string(), "application/json".to_string())
//! .with_body(b"{\"status\":\"ok\"}".to_vec());
//!
//! let test_response = TestResponse::Success(response);
//!
//! // Assert status
//! assert_status(&test_response, 200);
//!
//! // Assert headers
//! assert_header(&test_response, "Content-Type", "application/json");
//! ```
//!
//! ## Integration Testing with Database
//!
//! ```rust,ignore
//! use armature_testing::integration::*;
//! use std::sync::Arc;
//!
//! // Implement DatabaseTestHelper for your database
//! struct MyDbHelper;
//!
//! #[async_trait]
//! impl DatabaseTestHelper for MyDbHelper {
//! async fn setup(&self) -> Result<(), IntegrationTestError> {
//! // Create tables, seed data
//! Ok(())
//! }
//!
//! async fn teardown(&self) -> Result<(), IntegrationTestError> {
//! // Clean up
//! Ok(())
//! }
//! }
//!
//! // Use in tests
//! let fixture = TestFixture::new(Arc::new(MyDbHelper));
//! fixture.run_test(|| async {
//! // Your test code
//! Ok(())
//! }).await?;
//! ```
//!
//! ## Docker Test Containers
//!
//! ```rust,ignore
//! use armature_testing::docker::*;
//!
//! // Start Postgres container
//! let config = PostgresContainer::config("testdb", "user", "pass");
//! let mut container = DockerContainer::new(config);
//! container.start().await?;
//!
//! // Run tests...
//!
//! // Container automatically stops on drop
//! ```
//!
//! ## Load Testing
//!
//! ```rust,ignore
//! use armature_testing::load::*;
//!
//! let config = LoadTestConfig::new(10, 1000); // 10 concurrent, 1000 requests
//! let runner = LoadTestRunner::new(config, || async {
//! // Your test code
//! Ok(())
//! });
//!
//! let stats = runner.run().await?;
//! stats.print();
//! ```
//!
//! ## Contract Testing
//!
//! ```rust,ignore
//! use armature_testing::contract::*;
//!
//! // Create a contract
//! let request = ContractRequest::new(ContractMethod::Get, "/api/users/1");
//! let response = ContractResponse::new(200)
//! .with_body(serde_json::json!({"id": 1, "name": "Alice"}));
//!
//! let mut builder = ContractBuilder::new("Frontend", "Backend");
//! builder.add_interaction(ContractInteraction::new(
//! "get user by ID",
//! request,
//! response,
//! ));
//!
//! let contract = builder.build();
//!
//! // Save contract
//! let manager = ContractManager::new(PathBuf::from("./pacts"));
//! manager.save(&contract)?;
//! ```
// New modules
pub use ;
pub use ;
pub use ;
pub use ;
pub use TestContainer;
// Re-export common testing utilities
pub use test as tokio_test;
/// Prelude for common imports.
///
/// ```
/// use armature_testing::prelude::*;
/// ```