use oxdock_cli::{Step, StepKind, run_script};
use oxdock_fs::{GuardedPath, PathResolver};
#[cfg_attr(
miri,
ignore = "spawns subprocesses; process spawning not supported under Miri"
)]
#[test]
fn script_runs_copy_and_symlink() {
let temp = GuardedPath::tempdir().unwrap();
let root = temp.as_guarded_path().clone();
let resolver = PathResolver::new(root.as_path(), root.as_path()).unwrap();
resolver
.create_dir_all(&root.join("client/dist").unwrap())
.unwrap();
resolver
.create_dir_all(&root.join("server").unwrap())
.unwrap();
resolver
.write_file(&root.join("client/dist/test.txt").unwrap(), b"hello\n")
.unwrap();
let steps = vec![
Step {
guards: Vec::new(),
kind: StepKind::Workdir("client".into()),
scope_enter: 0,
scope_exit: 0,
},
Step {
guards: Vec::new(),
kind: StepKind::Run("echo ok".into()),
scope_enter: 0,
scope_exit: 0,
},
Step {
guards: Vec::new(),
kind: StepKind::Workdir("/".into()),
scope_enter: 0,
scope_exit: 0,
},
Step {
guards: Vec::new(),
kind: StepKind::Copy {
from: "./client/dist".into(),
to: "./client/dist-copy".into(),
},
scope_enter: 0,
scope_exit: 0,
},
Step {
guards: Vec::new(),
kind: StepKind::Symlink {
from: "./client/dist".into(),
to: "./server/dist".into(),
},
scope_enter: 0,
scope_exit: 0,
},
Step {
guards: Vec::new(),
kind: StepKind::Run("echo ok".into()),
scope_enter: 0,
scope_exit: 0,
},
];
run_script(&root, &steps).unwrap();
let copied = root.join("client/dist-copy/test.txt").unwrap();
assert!(copied.as_path().exists());
let contents = resolver.read_to_string(&copied).unwrap();
assert!(contents.contains("hello"));
#[cfg(unix)]
{
let linked = root.join("server/dist/test.txt").unwrap();
assert!(linked.as_path().exists());
}
#[cfg(not(unix))]
{
let linked_copy = root.join("server/dist/test.txt").unwrap();
assert!(linked_copy.as_path().exists());
}
}