Skip to content

Commit

Permalink
test(sim): skip sim tests if user not privileged
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Jul 1, 2024
1 parent e33299d commit 457823f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/trippy-core/tests/sim/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex, OnceLock};
use test_case::test_case;
use tokio::runtime::Runtime;
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
use tracing::{error, info, warn};
use tracing_subscriber::fmt::format::FmtSpan;

/// The maximum number of attempts for each test.
Expand Down Expand Up @@ -62,6 +62,11 @@ fn run_simulation_with_retry(simulation: Simulation) -> anyhow::Result<()> {
let runtime = runtime().lock().unwrap();
let simulation = Arc::new(simulation);
let name = simulation.name.clone();
if !trippy_privilege::Privilege::discover()?.has_privileges() {
// Skip if the current test as the user cannot create a tun device.
warn!("skipping test {}: insufficient privileges", name);
return Ok(());
}
for attempt in 1..=MAX_ATTEMPTS {
info!("start simulating {} [attempt #{}]", name, attempt);
if let Err(err) = runtime.block_on(run_simulation(simulation.clone())) {
Expand Down

0 comments on commit 457823f

Please sign in to comment.