Skip to content

Commit

Permalink
Merge pull request #1017 from cgwalters/test-progress
Browse files Browse the repository at this point in the history
tests: Add some sanity checking of --json-fd
  • Loading branch information
cgwalters authored Jan 8, 2025
2 parents c166df5 + d9f1c01 commit adf18ea
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/booted/test-image-pushpull-upgrade.nu
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ RUN echo test content > /usr/share/blah.txt
let orig_root_mtime = ls -Dl /ostree/bootc | get modified

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

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

# This just does some basic verification of the progress JSON
def sanity_check_switch_progress_json [data] {
let first = $data.0;
let event_count = $data | length
assert equal $first.type ProgressBytes
let steps = $first.stepsTotal
mut i = 0
for elt in $data {
if $elt.type != "ProgressBytes" {
break
}
# Bounds check steps
assert ($elt.steps <= $elt.stepsTotal)
assert equal $elt.stepsTotal $steps
$i += 1
}
let deploy = $data | get ($event_count - 1)
assert equal $deploy.steps 3
assert equal $deploy.stepsTotal 3
let deploy_tasks = $deploy.subtasks
assert equal ($deploy_tasks | length) 5
let deploy_names = $deploy_tasks | get subtask
assert equal $deploy_names ["merging", "deploying", "bound_images", "cleanup", "cleanup"]
}

# The second boot; verify we're in the derived image
def second_boot [] {
print "verifying second boot"
Expand Down

0 comments on commit adf18ea

Please sign in to comment.