Skip to content

Commit 6de9d4b

Browse files
committed
feat(test-utils): add fixture to set gw name
Adds a fixture so that we can annotate tests such that we make sure that the gateway name is seen as set from those tests. Sample: #[test] #[wrap(with_gw_name())] fn test_potato() { let gw_name = get_gw_name().unwrap(); println!("Hello {gw_name}"); } This is Daniel's. Signed-off-by: Fredi Raspall <[email protected]>
1 parent 1280286 commit 6de9d4b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test-utils/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! Testing utilities for the dataplane
55
66
use caps::{CapSet, Capability};
7+
use gwname::set_gw_name;
78
use rtnetlink::NetworkNamespace;
89
use std::panic::{RefUnwindSafe, UnwindSafe, catch_unwind};
910
use tracing::error;
@@ -126,6 +127,16 @@ pub fn with_caps<F: UnwindSafe + FnOnce() -> T, T>(
126127
}
127128
}
128129

130+
/// Fixture which sets the static gateway name to a known value common to all tests.
131+
pub fn with_gw_name<F: FnOnce() -> T, T>() -> impl FnOnce(F) -> T {
132+
move |f: F| {
133+
const TEST_GW_NAME: &str = "test-gw";
134+
println!("Setting gateway name to {TEST_GW_NAME}");
135+
set_gw_name(TEST_GW_NAME).unwrap();
136+
f()
137+
}
138+
}
139+
129140
/// Run an (async) function or closure in another network namespace.
130141
///
131142
/// This method will spawn a new thread and create a thread local tokio runtime to execute the

0 commit comments

Comments
 (0)