Skip to content

Commit

Permalink
Dump routing table for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
shutton committed Mar 7, 2024
1 parent 3a4be5f commit ca494a3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
run: cargo build
- name: Run tests
run: cargo test --verbose
run: cargo test --nocapture
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod routing_table;

use std::fmt::Write;

pub use routing_table::execute_netstat;

// Exports
pub use route_entry::RouteEntry;
pub use routing_flag::RoutingFlag;
Expand Down
5 changes: 3 additions & 2 deletions src/routing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl RoutingTable {
/// Returns an error if the `netstat` command fails to execute, or returns
/// unparseable output.
pub async fn load_from_netstat() -> Result<Self, Error> {
let output = query_netstat_routing_table().await?;
let output = execute_netstat().await?;
Self::from_netstat_output(&output)
}

Expand Down Expand Up @@ -122,7 +122,8 @@ impl RoutingTable {
}
}

async fn query_netstat_routing_table() -> Result<String, Error> {
/// Execute `netstat -rn` and return the output
pub async fn execute_netstat() -> Result<String, Error> {
let output = Command::new(NETSTAT_PATH)
.arg("-rn")
.stdin(std::process::Stdio::null())
Expand Down
17 changes: 17 additions & 0 deletions tests/live.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(clippy::missing_panics_doc)]

use anyhow::Result;
use macos_routing_table::{execute_netstat, RoutingTable};

#[tokio::test]
pub async fn main() -> Result<()> {
let raw = execute_netstat().await?;
eprintln!("Raw Table:");
eprintln!("----------");
eprint!("{raw}");
eprintln!("----------");
let table = RoutingTable::load_from_netstat().await?;
eprintln!("{table:?}");

Ok(())
}

0 comments on commit ca494a3

Please sign in to comment.