test(aya): iter: Disable the init system assertion in containers

It's hard to predict what's the PID of the first process in a container.
Use this assertion only on non-containerized systems.
reviewable/pr908/r8
Michal Rostecki 2 months ago
parent 613aaf8d7a
commit a77399393b

@ -1,4 +1,4 @@
use std::io::BufRead; use std::{env, io::BufRead, path::Path};
use aya::{programs::Iter, Btf, Ebpf}; use aya::{programs::Iter, Btf, Ebpf};
use test_log::test; use test_log::test;
@ -20,6 +20,9 @@ fn iter_task() {
let line_init = lines.next().unwrap().unwrap(); let line_init = lines.next().unwrap().unwrap();
assert_eq!(line_title, "tgid pid name"); assert_eq!(line_title, "tgid pid name");
// It's hard to predict what's the PID of the first process in a container.
// Use this assertion only on non-containerized systems.
if !Path::new("/.dockerenv").exists() && env::var_os("container").is_none() {
let expected_values = ["1 1 init", "1 1 systemd"]; let expected_values = ["1 1 init", "1 1 systemd"];
assert!( assert!(
expected_values.contains(&line_init.as_str()), expected_values.contains(&line_init.as_str()),
@ -27,4 +30,5 @@ fn iter_task() {
line_init, line_init,
expected_values expected_values
); );
}
} }

Loading…
Cancel
Save