updatehub_package_schema/definitions/
target_format.rs

1// Copyright (C) 2019 O.S. Systems Sofware LTDA
2//
3// SPDX-License-Identifier: Apache-2.0
4
5use serde::Deserialize;
6
7/// Information about formatting the partition before installing.
8#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Default)]
9#[serde(rename_all = "kebab-case")]
10pub struct TargetFormat {
11    #[serde(rename = "format?", default)]
12    pub should_format: bool,
13    pub format_options: Option<String>,
14}
15
16#[test]
17fn deserialize() {
18    use pretty_assertions::assert_eq;
19    use serde_json::json;
20
21    assert_eq!(
22        TargetFormat { should_format: true, format_options: Some("-fs ext2".to_string()) },
23        serde_json::from_value::<TargetFormat>(json!({
24            "format?": true,
25            "format-options": "-fs ext2"
26        }))
27        .unwrap()
28    );
29
30    assert_eq!(
31        TargetFormat { should_format: false, format_options: None },
32        serde_json::from_value::<TargetFormat>(json!({
33            "format?": false,
34        }))
35        .unwrap()
36    );
37}
38
39#[test]
40fn default() {
41    use pretty_assertions::assert_eq;
42
43    assert_eq!(
44        TargetFormat { should_format: false, format_options: None },
45        TargetFormat::default(),
46    );
47}