Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-core/src/integration/artifacts.rs
1use std::path::{Path, PathBuf};
2 
3pub const ARTIFACTS_KEY: &str = "test_artifacts";
4 
5pub const ARTIFACTS_DIR_ENV_VAR: &str = "WARP_INTEGRATION_TEST_ARTIFACTS_DIR";
6 
7pub struct TestArtifacts {
8 dir: PathBuf,
9}
10 
11impl TestArtifacts {
12 pub fn new(test_name: &str) -> Self {
13 let root = std::env::var(ARTIFACTS_DIR_ENV_VAR)
14 .map(PathBuf::from)
15 .unwrap_or_else(|_| std::env::temp_dir().join("warp_integration_test_artifacts"));
16 
17 let timestamp = chrono::Local::now().format("%Y-%m-%dT%H-%M-%S").to_string();
18 let dir = root.join(test_name).join(timestamp);
19 std::fs::create_dir_all(&dir).ok();
20 Self { dir }
21 }
22 
23 pub fn dir(&self) -> &Path {
24 &self.dir
25 }
26 
27 pub fn path(&self, filename: &str) -> PathBuf {
28 self.dir.join(filename)
29 }
30}
31 
32pub fn get_artifacts(step_data_map: &super::step::StepDataMap) -> Option<&TestArtifacts> {
33 step_data_map.get::<_, TestArtifacts>(ARTIFACTS_KEY)
34}
35