#![cfg(not(feature = "fetch"))]
use std::path::PathBuf;
use std::process::Command;
const PIN: &str = "sha256:0000000000000000000000000000000000000000000000000000000000000000";
fn scratch(case: &str) -> PathBuf {
let dir =
std::env::temp_dir().join(format!("headwater-no-fetch-{}-{case}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("the adopter root is made");
dir
}
fn vendor(case: &str, location: &str) -> (Option<i32>, String, bool) {
let root = scratch(case);
let output = Command::new(env!("CARGO_BIN_EXE_headwater"))
.args(["taxonomy", "vendor", location, "--expect", PIN, "--root"])
.arg(&root)
.output()
.expect("the binary runs");
let wrote = root.join(".headwater/packages").exists();
let _ = std::fs::remove_dir_all(&root);
(
output.status.code(),
String::from_utf8_lossy(&output.stderr).into_owned(),
wrote,
)
}
fn assert_refused(case: &str, location: &str) {
let (code, stderr, wrote) = vendor(case, location);
assert_eq!(code, Some(1), "a location was not refused:\n{stderr}");
assert!(
stderr.contains("built without the `fetch` feature"),
"the refusal does not say why:\n{stderr}"
);
assert!(
stderr.contains("taxonomy vendor <dir> --expect <digest>"),
"the refusal does not name the path form:\n{stderr}"
);
assert!(!wrote, "a refused vendor wrote into the package area");
}
#[test]
fn a_binary_without_the_fetch_refuses_an_https_location() {
assert_refused("https", "https://example.invalid/x.zip");
}
#[test]
fn a_binary_without_the_fetch_refuses_an_upper_case_http_location() {
assert_refused("upper-http", "HTTP://127.0.0.1:9/x.zip");
}