storkit: merge 444_refactor_extract_shared_test_helpers_test_ctx_write_story_file_make_api
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//! Shared test utilities for I/O module tests.
|
||||
//!
|
||||
//! Import with `use crate::io::test_helpers::{create_test_files, setup_project};`
|
||||
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
|
||||
/// Create a minimal storkit project directory structure under `dir`.
|
||||
///
|
||||
/// Creates `.storkit/specs/tech/` and `script/`, then returns the root path.
|
||||
/// Used by onboarding and wizard tests.
|
||||
pub(crate) fn setup_project(dir: &TempDir) -> PathBuf {
|
||||
let root = dir.path().to_path_buf();
|
||||
let sk = root.join(".storkit");
|
||||
fs::create_dir_all(sk.join("specs").join("tech")).unwrap();
|
||||
fs::create_dir_all(root.join("script")).unwrap();
|
||||
root
|
||||
}
|
||||
|
||||
/// Write a set of files into `dir` at the given relative paths.
|
||||
///
|
||||
/// Parent directories are created automatically. Used by search tests.
|
||||
pub(crate) fn create_test_files(dir: &TempDir, files: &[(&str, &str)]) {
|
||||
for (path, content) in files {
|
||||
let full = dir.path().join(path);
|
||||
if let Some(parent) = full.parent() {
|
||||
fs::create_dir_all(parent).unwrap();
|
||||
}
|
||||
fs::write(full, content).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user