81 lines
2.6 KiB
Rust
81 lines
2.6 KiB
Rust
//! Two small texts from the M3b review: every line `brokerd serve` prints about its runtime starts
|
|
//! with `brokerd:`, and a bad `[runner]` value is quoted in its error. Do not edit.
|
|
|
|
#[path = "support/fake_podman.rs"]
|
|
mod fake_podman;
|
|
|
|
use std::io::Read;
|
|
use std::os::unix::net::UnixStream;
|
|
use std::process::{Command, Stdio};
|
|
use std::time::{Duration, Instant};
|
|
|
|
use brokerd::config::{Config, ConfigError};
|
|
use fake_podman::{Fake, IMAGE, serial};
|
|
|
|
#[test]
|
|
fn the_runtime_notice_starts_with_brokerd() {
|
|
let _s = serial();
|
|
let fake = Fake::new("notice", "exit 0");
|
|
let home = fake.dir.join("home");
|
|
std::fs::create_dir_all(home.join("grants")).unwrap();
|
|
let config = fake.dir.join("brokerd.toml");
|
|
std::fs::write(
|
|
&config,
|
|
format!(
|
|
"[paths]\nhome = \"{0}\"\ngrants = \"{0}/grants\"\n[runner]\npodman = \"{1}\"\nimage = \"{IMAGE}\"\n",
|
|
home.display(),
|
|
fake.script.display()
|
|
),
|
|
)
|
|
.unwrap();
|
|
let mut child = Command::new(env!("CARGO_BIN_EXE_brokerd"))
|
|
.args(["serve", "--config"])
|
|
.arg(&config)
|
|
.stderr(Stdio::piped())
|
|
.spawn()
|
|
.unwrap();
|
|
let until = Instant::now() + Duration::from_secs(10);
|
|
while UnixStream::connect(home.join("run/loop-broker/broker.sock")).is_err() {
|
|
assert!(Instant::now() < until, "brokerd never listened");
|
|
std::thread::sleep(Duration::from_millis(20));
|
|
}
|
|
std::thread::sleep(Duration::from_millis(100));
|
|
child.kill().unwrap();
|
|
child.wait().unwrap();
|
|
let mut printed = String::new();
|
|
child
|
|
.stderr
|
|
.take()
|
|
.unwrap()
|
|
.read_to_string(&mut printed)
|
|
.unwrap();
|
|
assert!(
|
|
printed
|
|
.lines()
|
|
.any(|l| l == format!("brokerd: tools run in containers from {IMAGE}")),
|
|
"{printed}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_bad_runner_value_is_quoted() {
|
|
let dir = std::env::temp_dir().join(format!("bx-notice-cfg-{}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
let cases = [
|
|
("image = \"not by digest\"", "\"not by digest\""),
|
|
(
|
|
&*format!("image = \"{IMAGE}\"\nmemory = \"lots\""),
|
|
"\"lots\"",
|
|
),
|
|
];
|
|
for (n, (body, quoted)) in cases.iter().enumerate() {
|
|
let path = dir.join(format!("q{n}.toml"));
|
|
std::fs::write(&path, format!("[runner]\n{body}\n")).unwrap();
|
|
match Config::load(&path) {
|
|
Err(ConfigError::Invalid(_, why)) => assert!(why.contains(quoted), "{why}"),
|
|
other => panic!("{body}: {other:?}"),
|
|
}
|
|
}
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
}
|