blob: d0a26458e4505d4926a258428718e01da0521200 (
plain)
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
|
//! Test isolation utilities
use std::sync::atomic::{AtomicU64, Ordering};
static TEST_COUNTER: AtomicU64 = AtomicU64::new(0);
/// Generate a unique test ID
pub fn generate_test_id() -> String {
let counter = TEST_COUNTER.fetch_add(1, Ordering::SeqCst);
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
format!("test-{}-{}", timestamp, counter)
}
/// Generate a unique audit run ID for CI
pub fn generate_ci_run_id() -> String {
format!("ci-{}", &uuid::Uuid::new_v4().to_string()[..8])
}
/// Generate a unique audit run ID for production
pub fn generate_prod_run_id() -> String {
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
format!("prod-audit-{}", timestamp)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_test_id() {
let id1 = generate_test_id();
let id2 = generate_test_id();
assert_ne!(id1, id2);
assert!(id1.starts_with("test-"));
}
#[test]
fn test_generate_ci_run_id() {
let id = generate_ci_run_id();
assert!(id.starts_with("ci-"));
}
#[test]
fn test_generate_prod_run_id() {
let id = generate_prod_run_id();
assert!(id.starts_with("prod-audit-"));
}
}
|