simbld_http/utils/
test_helpers.rs

1use lazy_static::lazy_static;
2use std::sync::Mutex;
3
4// Lazy static mutex to store the output of a test
5lazy_static! {
6    static ref BUFFER_OUTPUT: Mutex<Vec<String>> = Mutex::new(Vec::new());
7}
8
9// Function to capture the output of a test
10pub fn capture_test<F: FnOnce()>(func: F) -> Vec<String> {
11  let mut buffer = BUFFER_OUTPUT.lock().unwrap();
12  buffer.clear();
13  
14  func();
15  
16  buffer.clone()
17}
18
19// Function to push a message to the buffer
20pub fn push_to_buffer(msg: String) {
21  let mut buffer = BUFFER_OUTPUT.lock().unwrap();
22  buffer.push(msg);
23}
24
25// Function to get the content of the buffer
26pub fn get_buffer_content() -> Vec<String> {
27  BUFFER_OUTPUT.lock().unwrap().clone()
28}