Skip to content

Commit adf18ea

Browse files
authored
Merge pull request #1017 from cgwalters/test-progress
tests: Add some sanity checking of --json-fd
2 parents c166df5 + d9f1c01 commit adf18ea

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/booted/test-image-pushpull-upgrade.nu

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,20 @@ RUN echo test content > /usr/share/blah.txt
5050
let orig_root_mtime = ls -Dl /ostree/bootc | get modified
5151

5252
# Now, fetch it back into the bootc storage!
53-
bootc switch --transport containers-storage localhost/bootc-derived
53+
# We also test the progress API here
54+
let tmpdir = mktemp -d -t bootc-progress.XXXXXX
55+
let progress_fifo = $"($tmpdir)/progress.fifo"
56+
let progress_json = $"($tmpdir)/progress.json"
57+
mkfifo $progress_fifo
58+
# nushell doesn't support & (for good reasons) so fork off a copy task via systemd-run
59+
# which reads from the fifo and writes to a file
60+
try { systemctl kill test-cat-progress }
61+
systemd-run -u test-cat-progress -- /bin/bash -c $"exec cat ($progress_fifo) > ($progress_json)"
62+
# nushell doesn't do fd passing right now either, so run via bash
63+
bash -c $"bootc switch --json-fd 3 --transport containers-storage localhost/bootc-derived 3>($progress_fifo)"
64+
# Now, let's do some checking of the progress json
65+
let progress = open --raw $progress_json | from json -o
66+
sanity_check_switch_progress_json $progress
5467

5568
# Also test that the mtime changes on modification
5669
let new_root_mtime = ls -Dl /ostree/bootc | get modified
@@ -60,6 +73,31 @@ RUN echo test content > /usr/share/blah.txt
6073
tmt-reboot
6174
}
6275

76+
# This just does some basic verification of the progress JSON
77+
def sanity_check_switch_progress_json [data] {
78+
let first = $data.0;
79+
let event_count = $data | length
80+
assert equal $first.type ProgressBytes
81+
let steps = $first.stepsTotal
82+
mut i = 0
83+
for elt in $data {
84+
if $elt.type != "ProgressBytes" {
85+
break
86+
}
87+
# Bounds check steps
88+
assert ($elt.steps <= $elt.stepsTotal)
89+
assert equal $elt.stepsTotal $steps
90+
$i += 1
91+
}
92+
let deploy = $data | get ($event_count - 1)
93+
assert equal $deploy.steps 3
94+
assert equal $deploy.stepsTotal 3
95+
let deploy_tasks = $deploy.subtasks
96+
assert equal ($deploy_tasks | length) 5
97+
let deploy_names = $deploy_tasks | get subtask
98+
assert equal $deploy_names ["merging", "deploying", "bound_images", "cleanup", "cleanup"]
99+
}
100+
63101
# The second boot; verify we're in the derived image
64102
def second_boot [] {
65103
print "verifying second boot"

0 commit comments

Comments
 (0)