crates/dwarves-slsa/tests/release_mode_env.rs
//! `DWARVES_RELEASE_MODE=1` puts the process in release mode: a lane's `build` (and the
//! Build Thing path, which goes through the same `build_release`) is refused. One test
//! in its own binary, because it sets the environment.
use std::collections::BTreeMap;
struct Never;
impl dwarves_slsa::runner::Executor for Never {
fn execute(
&self,
_: &dwarves_runa::Pipeline,
_: std::sync::Arc<dwarves_slsa::runner::ReleaseRun>,
_: &str,
) -> dwarves_slsa::Result<dwarves_slsa::runner::RunRecord> {
panic!("release mode builds nothing from a lane")
}
}
#[test]
fn the_release_mode_variable_refuses_a_lanes_build() {
std::env::set_var("DWARVES_RELEASE_MODE", "1");
let spec = dwarves_slsa::spec::ReleaseSpec::parse(&format!(
r#"name = "holger-2.0.1"
image = "{}"
lock = ["holger/Cargo.toml"]
[[repo]]
name = "holger"
org = "nordisk"
commit = "87e5ada50ab5745464e4b46305bfd62d0460f52c"
[[crate]]
name = "holger-errcode"
version = "2.0.1"
repo = "holger"
path = "errcode"
"#,
dwarves_slsa::runner::DEFAULT_IMAGE
))
.unwrap();
let d = tempfile::tempdir().unwrap();
let e = dwarves_slsa::cli::build_release(
&spec,
Some(d.path().join("run")),
None,
false,
false,
&BTreeMap::new(),
&Never,
)
.unwrap_err();
assert!(e.0.contains("inbox"), "{e}");
// Nothing was made.
assert!(!d.path().join("run").exists());
}