Skip to content

Commit d5de0e0

Browse files
committed
nat: Make tests work
Import YAML files used for tests in the NAT module. Fix path handling for pointing to these YAML files in the code, and also fix dependencies imports for running the tests. Signed-off-by: Quentin Monnet <[email protected]>
1 parent fb4140b commit d5de0e0

File tree

8 files changed

+85
-8
lines changed

8 files changed

+85
-8
lines changed

Cargo.lock

Lines changed: 53 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ thiserror = { version = "2.0.11", default-features = false, features = [] }
4242
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
4343
tracing-subscriber = { version = "0.3.19", default-features = false, features = []}
4444

45+
# dev-dependencies
46+
tracing-test = { version = "0.2.5", default-features = false, features = [] }
47+
4548
[profile.dev]
4649
panic = "unwind"
4750

dataplane/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ serde = { workspace = true, features = ["derive"] }
1414
serde_yml = { workspace = true }
1515
tracing = { workspace = true }
1616
tracing-subscriber = { workspace = true, features = ["default"] }
17+
18+
[dev-dependencies]
19+
tracing-test = { workspace = true }

dataplane/src/nat.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fmt::Debug;
88
use std::fs;
99
use std::hash::Hash;
1010
use std::net::IpAddr;
11+
use std::path::Path;
1112
use tracing::{error, warn};
1213

1314
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
@@ -216,7 +217,7 @@ impl GlobalContext {
216217
}
217218

218219
#[tracing::instrument(level = "info")]
219-
fn load_vpcs(&mut self, directory: &str) {
220+
fn load_vpcs(&mut self, directory: &Path) {
220221
let paths = fs::read_dir(directory).expect("Failed to read VPCs directory");
221222

222223
for entry in paths.flatten() {
@@ -233,7 +234,7 @@ impl GlobalContext {
233234
}
234235

235236
#[tracing::instrument(level = "info")]
236-
fn load_pifs(&mut self, directory: &str) {
237+
fn load_pifs(&mut self, directory: &Path) {
237238
let paths = fs::read_dir(directory).expect("Failed to read PIFs directory");
238239

239240
for entry in paths.flatten() {
@@ -275,7 +276,7 @@ impl GlobalContext {
275276
#[cfg(test)]
276277
mod tests {
277278
use super::*;
278-
use tracing::{error, info, warn};
279+
use tracing::{info, warn};
279280
use tracing_test::traced_test;
280281

281282
#[test]
@@ -288,8 +289,8 @@ mod tests {
288289
pwd = std::env::current_dir().unwrap().display()
289290
);
290291
// Load VPCs and PIFs
291-
context.load_vpcs("vpcs");
292-
context.load_pifs("pifs");
292+
context.load_vpcs(&Path::new("src").join("nat").join("vpcs").as_path());
293+
context.load_pifs(&Path::new("src").join("nat").join("pifs").as_path());
293294

294295
// Example global lookup
295296
let ip: IpAddr = "11.11.0.5".parse().unwrap();

dataplane/src/nat/pifs/pif-1.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: PIF1
2+
vni: 3000
3+
endpoints:
4+
- [192.168.1.1, 32]
5+
- [192.168.1.0, 24]
6+
ips:
7+
- [10.10.0.0, 24]
8+
vpc: VPC1

dataplane/src/nat/pifs/pif-2.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: PIF2
2+
vni: 4000
3+
endpoints:
4+
- [10.0.0.1, 32]
5+
- [10.0.0.0, 24]
6+
ips:
7+
- [11.11.0.0, 24]
8+
vpc: VPC2

dataplane/src/nat/vpcs/vpc1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: VPC1
2+
vni: 100

dataplane/src/nat/vpcs/vpc2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: VPC2
2+
vni: 200

0 commit comments

Comments
 (0)