@@ -11,7 +11,7 @@ pub const PIXI_PACK_METADATA_PATH: &str = "pixi-pack.json";
11
11
pub const DEFAULT_PIXI_PACK_VERSION : & str = "1" ;
12
12
13
13
/// The metadata for a "pixi-pack".
14
- #[ derive( Serialize , Deserialize , Debug , Clone ) ]
14
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Eq ) ]
15
15
pub struct PixiPackMetadata {
16
16
/// The pack format version.
17
17
pub version : String ,
@@ -27,3 +27,36 @@ impl Default for PixiPackMetadata {
27
27
}
28
28
}
29
29
}
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