Skip to content

Commit f87e442

Browse files
committed
Add serialization tests
1 parent c80be3e commit f87e442

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/lib.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const PIXI_PACK_METADATA_PATH: &str = "pixi-pack.json";
1111
pub const DEFAULT_PIXI_PACK_VERSION: &str = "1";
1212

1313
/// The metadata for a "pixi-pack".
14-
#[derive(Serialize, Deserialize, Debug, Clone)]
14+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
1515
pub struct PixiPackMetadata {
1616
/// The pack format version.
1717
pub version: String,
@@ -27,3 +27,36 @@ impl Default for PixiPackMetadata {
2727
}
2828
}
2929
}
30+
31+
/* --------------------------------------------------------------------------------------------- */
32+
/* TESTS */
33+
/* --------------------------------------------------------------------------------------------- */
34+
35+
#[cfg(test)]
36+
mod tests {
37+
use super::*;
38+
use rstest::*;
39+
use serde_json::{json, Value};
40+
41+
#[rstest]
42+
fn test_metadata_serialization() {
43+
let metadata = PixiPackMetadata {
44+
version: DEFAULT_PIXI_PACK_VERSION.to_string(),
45+
platform: Platform::Linux64,
46+
};
47+
let result = json!(metadata).to_string();
48+
assert_eq!(result, "{\"version\":\"1\",\"platform\":\"linux-64\"}");
49+
assert_eq!(
50+
serde_json::from_str::<PixiPackMetadata>(&result).unwrap(),
51+
metadata
52+
);
53+
}
54+
55+
#[rstest]
56+
#[case(json!({"version": "1", "platform": "linux64"}))]
57+
#[case(json!({"version": 1.0, "platform": "linux-64"}))]
58+
#[case(json!({"version": 1, "platform": "linux-64"}))]
59+
fn test_metadata_serialization_failure(#[case] invalid: Value) {
60+
assert!(serde_json::from_str::<PixiPackMetadata>(&invalid.to_string()).is_err());
61+
}
62+
}

0 commit comments

Comments
 (0)