Skip to content

Commit

Permalink
tests: test for error when deleting unknown table
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhb committed Aug 12, 2023
1 parent 1d6a5e2 commit 1bd71ea
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/helper_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use nftables::{batch::Batch, expr, helper, schema, types};
use nftables::{
batch::Batch,
expr,
helper::{self, NftablesError},
schema, types,
};

#[test]
#[ignore]
Expand All @@ -15,6 +20,22 @@ fn test_apply_ruleset() {
nftables::helper::apply_ruleset(&ruleset, None, None).unwrap();
}

#[test]
#[ignore]
/// Attempts to delete an unknown table, expecting an error.
fn test_remove_unknown_table() {
let mut batch = Batch::new();
batch.delete(schema::NfListObject::Table(schema::Table::new(
types::NfFamily::IP6,
"i-do-not-exist".to_string(),
)));
let ruleset = batch.to_nftables();

let result = nftables::helper::apply_ruleset(&ruleset, None, None);
let err = result.expect_err("Expecting nftables error for unknown table.");
assert!(matches!(err, NftablesError::NftFailed { .. }));
}

fn example_ruleset() -> schema::Nftables {
let mut batch = Batch::new();
let table_name = "test-table-01".to_string();
Expand Down Expand Up @@ -53,3 +74,4 @@ fn example_ruleset() -> schema::Nftables {
)));
batch.to_nftables()
}

0 comments on commit 1bd71ea

Please sign in to comment.