Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmynk committed Nov 21, 2023
1 parent fd4fcab commit c5a5edf
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
18 changes: 15 additions & 3 deletions examples/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,30 @@ fn send_request(socket: &Socket, message: RtnlMessage) {

fn main() {
let messages = get_qdiscs();
let qdiscs = ParseOptions::new().tc(messages).unwrap();
let qdiscs = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages).unwrap();
println!("length: {}, qdiscs: {:#?}", qdiscs.len(), qdiscs);

let messages = get_links();
let links = ParseOptions::new().links(messages).unwrap();
let links = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.links(messages).unwrap();
println!("length: {}, links: {:#?}", links.len(), links);

let mut messages = Vec::new();
for link in links {
let classes = get_classes(link.index as i32);
messages.extend(classes);
}
let classes = ParseOptions::new().tc(messages).unwrap();
let classes = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages).unwrap();
println!("length: {}, classes: {:#?}", classes.len(), classes);
}
29 changes: 24 additions & 5 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use super::*;
#[test]
fn test_no_queue() {
let messages = vec![get_qdiscs()[0].clone()];
let stats = ParseOptions::new().tc(messages).unwrap();
let stats = ParseOptions::new()
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages)
.unwrap();

let tc = stats.get(0).unwrap();
// message
Expand All @@ -33,7 +37,11 @@ fn test_no_queue() {
#[test]
fn test_mq() {
let messages = vec![get_qdiscs()[1].clone()];
let stats = ParseOptions::new().tc(messages).unwrap();
let stats = ParseOptions::new()
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages)
.unwrap();

let tc = stats.get(0).unwrap();
// message
Expand All @@ -56,7 +64,11 @@ fn test_mq() {
#[test]
fn test_fq_codel() {
let messages = vec![get_qdiscs()[2].clone()];
let stats = ParseOptions::new().tc(messages).unwrap();
let stats = ParseOptions::new()
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages)
.unwrap();

let tc = stats.get(0).unwrap();
// message
Expand Down Expand Up @@ -114,7 +126,11 @@ fn test_htb() {
let qdiscs = get_qdiscs();
let classes = get_classes();
let messages = vec![qdiscs[3].clone(), classes[0].clone()];
let tc_stats = ParseOptions::new().tc(messages).unwrap();
let tc_stats = ParseOptions::new()
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages)
.unwrap();

let tc = tc_stats.get(0).unwrap();
// message
Expand Down Expand Up @@ -253,7 +269,10 @@ fn test_stats_parse_fail() {
NetlinkHeader::default(),
NetlinkPayload::InnerMessage(RtnlMessage::NewQueueDiscipline(tc_message)),
);
let tcs = ParseOptions::new().tc(vec![messages]).unwrap();
let tcs = ParseOptions::new()
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(vec![messages]).unwrap();
let tc = tcs.get(0).unwrap();
assert!(tc.attr.stats2.is_none());
}
Expand Down
20 changes: 17 additions & 3 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ fn send_request(socket: &Socket, message: RtnlMessage) {
#[test]
fn test_qdiscs() {
let messages = get_qdiscs();
let tcs = ParseOptions::new().tc(messages).unwrap();
let tcs = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages)
.unwrap();
for tc in tcs {
let attr = tc.attr;
assert!(!attr.kind.is_empty());
Expand All @@ -89,13 +94,22 @@ fn test_qdiscs() {
#[test]
fn test_link_classes() {
let messages = get_links();
let links = ParseOptions::new().links(messages).unwrap();
let links = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.links(messages)
.unwrap();

assert!(!links.is_empty());

for link in links {
let messages = get_classes(link.index);
let classes = ParseOptions::new().tc(messages);
let classes = ParseOptions::new()
.fail_on_unknown_netlink_message(false)
.fail_on_unknown_attribute(false)
.fail_on_unknown_option(false)
.tc(messages);
assert!(classes.is_ok());
}
}

0 comments on commit c5a5edf

Please sign in to comment.