Skip to content

Commit

Permalink
Fix queue JSON serialisation when flag is none
Browse files Browse the repository at this point in the history
  • Loading branch information
noelatmerqury committed Jul 7, 2023
1 parent d08001f commit 4f42782
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ pub struct Queue {
/// Queue number.
pub num: Expression,

#[serde(skip_serializing_if = "Option::is_none")]
/// Queue flags.
pub flags: Option<HashSet<QueueFlag>>,
}
Expand Down
11 changes: 11 additions & 0 deletions tests/json_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,14 @@ fn test_parsing_of_queue_without_flags() {
let parsed: Nftables = serde_json::from_value(json).unwrap();
assert_eq!(expected, parsed);
}

#[test]
fn test_queue_json_serialisation() {
let queue = Statement::Queue(Queue {
num: Expression::Number(0),
flags: None,
});

let expected_json = String::from(r#"{"queue":{"num":0}}"#);
assert_eq!(expected_json, serde_json::to_string(&queue).unwrap());
}

0 comments on commit 4f42782

Please sign in to comment.