Skip to content

Commit 016ce23

Browse files
authored
Merge pull request #1213 from rsturla/followup-status-booted-tests
tests(status): add tests for --booted
2 parents 244c1a0 + ce3bb65 commit 016ce23

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/src/spec.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,49 @@ mod tests {
316316
assert!(Store::from_str("OstrEeContAiner", true).is_ok());
317317
assert!(Store::from_str("invalid", true).is_err());
318318
}
319+
320+
#[test]
321+
fn test_host_filter_to_slot() {
322+
fn create_host() -> Host {
323+
let mut host = Host::default();
324+
host.status.staged = Some(default_boot_entry());
325+
host.status.booted = Some(default_boot_entry());
326+
host.status.rollback = Some(default_boot_entry());
327+
host
328+
}
329+
330+
fn default_boot_entry() -> BootEntry {
331+
BootEntry {
332+
image: None,
333+
cached_update: None,
334+
incompatible: false,
335+
pinned: false,
336+
store: None,
337+
ostree: None,
338+
}
339+
}
340+
341+
fn assert_host_state(
342+
host: &Host,
343+
staged: Option<BootEntry>,
344+
booted: Option<BootEntry>,
345+
rollback: Option<BootEntry>,
346+
) {
347+
assert_eq!(host.status.staged, staged);
348+
assert_eq!(host.status.booted, booted);
349+
assert_eq!(host.status.rollback, rollback);
350+
}
351+
352+
let mut host = create_host();
353+
host.filter_to_slot(Slot::Staged);
354+
assert_host_state(&host, Some(default_boot_entry()), None, None);
355+
356+
let mut host = create_host();
357+
host.filter_to_slot(Slot::Booted);
358+
assert_host_state(&host, None, Some(default_boot_entry()), None);
359+
360+
let mut host = create_host();
361+
host.filter_to_slot(Slot::Rollback);
362+
assert_host_state(&host, None, None, Some(default_boot_entry()));
363+
}
319364
}

tests/booted/readonly/001-test-status.nu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ tap begin "verify bootc status output formats"
55

66
let st = bootc status --json | from json
77
assert equal $st.apiVersion org.containers.bootc/v1
8+
89
let st = bootc status --json --format-version=0 | from json
910
assert equal $st.apiVersion org.containers.bootc/v1
11+
1012
let st = bootc status --format=yaml | from yaml
1113
assert equal $st.apiVersion org.containers.bootc/v1
1214
assert ($st.status.booted.image.timestamp != null)
15+
16+
let st = bootc status --json --booted | from json
17+
assert equal $st.apiVersion org.containers.bootc/v1
18+
assert ($st.status.booted.image.timestamp != null)
19+
assert (($st.status | get rollback | default null) == null)
20+
assert (($st.status | get staged | default null) == null)
21+
1322
tap ok

0 commit comments

Comments
 (0)