diff --git a/lib/src/spec.rs b/lib/src/spec.rs index c712916a..bbef9234 100644 --- a/lib/src/spec.rs +++ b/lib/src/spec.rs @@ -316,4 +316,49 @@ mod tests { assert!(Store::from_str("OstrEeContAiner", true).is_ok()); assert!(Store::from_str("invalid", true).is_err()); } + + #[test] + fn test_host_filter_to_slot() { + fn create_host() -> Host { + let mut host = Host::default(); + host.status.staged = Some(default_boot_entry()); + host.status.booted = Some(default_boot_entry()); + host.status.rollback = Some(default_boot_entry()); + host + } + + fn default_boot_entry() -> BootEntry { + BootEntry { + image: None, + cached_update: None, + incompatible: false, + pinned: false, + store: None, + ostree: None, + } + } + + fn assert_host_state( + host: &Host, + staged: Option, + booted: Option, + rollback: Option, + ) { + assert_eq!(host.status.staged, staged); + assert_eq!(host.status.booted, booted); + assert_eq!(host.status.rollback, rollback); + } + + let mut host = create_host(); + host.filter_to_slot(Slot::Staged); + assert_host_state(&host, Some(default_boot_entry()), None, None); + + let mut host = create_host(); + host.filter_to_slot(Slot::Booted); + assert_host_state(&host, None, Some(default_boot_entry()), None); + + let mut host = create_host(); + host.filter_to_slot(Slot::Rollback); + assert_host_state(&host, None, None, Some(default_boot_entry())); + } } diff --git a/tests/booted/readonly/001-test-status.nu b/tests/booted/readonly/001-test-status.nu index 6c799cc2..727b8a6f 100644 --- a/tests/booted/readonly/001-test-status.nu +++ b/tests/booted/readonly/001-test-status.nu @@ -5,9 +5,18 @@ tap begin "verify bootc status output formats" let st = bootc status --json | from json assert equal $st.apiVersion org.containers.bootc/v1 + let st = bootc status --json --format-version=0 | from json assert equal $st.apiVersion org.containers.bootc/v1 + let st = bootc status --format=yaml | from yaml assert equal $st.apiVersion org.containers.bootc/v1 assert ($st.status.booted.image.timestamp != null) + +let st = bootc status --json --booted | from json +assert equal $st.apiVersion org.containers.bootc/v1 +assert ($st.status.booted.image.timestamp != null) +assert (($st.status | get rollback | default null) == null) +assert (($st.status | get staged | default null) == null) + tap ok