Skip to content

Commit c0051ab

Browse files
committed
install/aleph: skip serializing optional fields if None
This avoids writing out fields with `null` values. See coreos/bootupd#1166. Signed-off-by: Rolv Apneseth <rolv.apneseth@gmail.com>
1 parent de7ae55 commit c0051ab

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎crates/lib/src/install/aleph.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ pub(crate) struct InstallAleph {
3131
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
3232
pub(crate) labels: BTreeMap<String, String>,
3333
/// The version number
34+
#[serde(skip_serializing_if = "Option::is_none")]
3435
pub(crate) version: Option<String>,
3536
/// The timestamp
37+
#[serde(skip_serializing_if = "Option::is_none")]
3638
pub(crate) timestamp: Option<chrono::DateTime<chrono::Utc>>,
3739
/// The `uname -r` of the kernel doing the installation
3840
pub(crate) kernel: String,

‎tmt/tests/booted/readonly/013-test-aleph.nu‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ if $is_composefs {
7171
let bootc_label = $labels | get "containers.bootc"
7272
assert ($bootc_label | is-not-empty) "containers.bootc label should be present"
7373
}
74+
75+
# The version field is optional (skip_serializing_if = Option::is_none),
76+
# but if present it should match the booted image's version.
77+
let version = $aleph.version? | default null
78+
if $version != null {
79+
assert ($version | is-not-empty) "version field, if present, should be non-empty"
80+
let booted_version = $booted.image.version
81+
assert equal $version $booted_version "version should match the booted image's version"
82+
}
83+
84+
# The timestamp field may be absent if empty (skip_serializing_if), but if
85+
# present it should match the booted image's timestamp.
86+
let timestamp = $aleph.timestamp? | default null
87+
if $timestamp != null {
88+
assert ($timestamp | is-not-empty) "timestamp field, if present, should be non-empty"
89+
let booted_timestamp = $booted.image.timestamp
90+
assert equal $timestamp $booted_timestamp "timestamp should match the booted image's timestamp"
91+
}
7492
}
7593

7694
tap ok

0 commit comments

Comments
 (0)