upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/isolation.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 06:17:55 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 06:17:55 +0000
commit001ca45e385c05b0eaa36d9879e051853aaff107 (patch)
tree603fb85d2563db5b7c418e9fd143d479bd09676e /grasp-audit/src/isolation.rs
parentd428baf30feec295870fadda2d335d1e7f89507b (diff)
created POC grasp-auditor
Diffstat (limited to 'grasp-audit/src/isolation.rs')
-rw-r--r--grasp-audit/src/isolation.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/grasp-audit/src/isolation.rs b/grasp-audit/src/isolation.rs
new file mode 100644
index 0000000..298781a
--- /dev/null
+++ b/grasp-audit/src/isolation.rs
@@ -0,0 +1,57 @@
1//! Test isolation utilities
2
3use std::sync::atomic::{AtomicU64, Ordering};
4
5static TEST_COUNTER: AtomicU64 = AtomicU64::new(0);
6
7/// Generate a unique test ID
8pub fn generate_test_id() -> String {
9 let counter = TEST_COUNTER.fetch_add(1, Ordering::SeqCst);
10 let timestamp = std::time::SystemTime::now()
11 .duration_since(std::time::UNIX_EPOCH)
12 .unwrap()
13 .as_secs();
14
15 format!("test-{}-{}", timestamp, counter)
16}
17
18/// Generate a unique audit run ID for CI
19pub fn generate_ci_run_id() -> String {
20 format!("ci-{}", uuid::Uuid::new_v4())
21}
22
23/// Generate a unique audit run ID for production
24pub fn generate_prod_run_id() -> String {
25 let timestamp = std::time::SystemTime::now()
26 .duration_since(std::time::UNIX_EPOCH)
27 .unwrap()
28 .as_secs();
29
30 format!("prod-audit-{}", timestamp)
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_generate_test_id() {
39 let id1 = generate_test_id();
40 let id2 = generate_test_id();
41
42 assert_ne!(id1, id2);
43 assert!(id1.starts_with("test-"));
44 }
45
46 #[test]
47 fn test_generate_ci_run_id() {
48 let id = generate_ci_run_id();
49 assert!(id.starts_with("ci-"));
50 }
51
52 #[test]
53 fn test_generate_prod_run_id() {
54 let id = generate_prod_run_id();
55 assert!(id.starts_with("prod-audit-"));
56 }
57}