Skip to content

Commit

Permalink
Merge pull request #93 from lucab/push-xwkvyrnzmvtt
Browse files Browse the repository at this point in the history
caps: improve serde tests
  • Loading branch information
lucab authored Feb 26, 2025
2 parents 1277a9c + 5a7d577 commit 757ae11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
with:
toolchain: "stable"
default: true
- name: cargo build
run: cargo build
- name: cargo test
run: cargo test
- name: cargo build --all-features
run: cargo build --all-features
- name: cargo test --all-features
run: cargo test --all-features
tests-release-stable:
name: "Tests (release), stable toolchain"
runs-on: ubuntu-latest
Expand Down
22 changes: 18 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,23 @@ mod tests {
#[test]
#[cfg(feature = "serde_support")]
fn test_serde() {
let p1 = Capability::from_str("CAP_CHOWN").unwrap();
let ser = serde_json::to_value(&p1).unwrap();
let deser: Capability = serde_json::from_value(ser).unwrap();
assert_eq!(deser, p1);
let input = "CAP_CHOWN";
// Serialization
{
let p1 = Capability::from_str(input).unwrap();
let ser = serde_json::to_value(&p1).unwrap();
let json_str = ser.as_str().unwrap();
assert_eq!(json_str, input);
let deser: Capability = serde_json::from_value(ser).unwrap();
assert_eq!(deser, p1);
}
// Deserialization
{
let json_input = format!(r#""{}""#, input);
let deser: Capability = serde_json::from_str(&json_input).unwrap();
let ser = serde_json::to_value(&deser).unwrap();
let json_str = ser.as_str().unwrap();
assert_eq!(json_str, input);
}
}
}

0 comments on commit 757ae11

Please sign in to comment.