summary: Ensure `snap debug bootvars` command works

details: |
    This test checks the command `snap debug bootvars` displays
    correct boot variables information.

debug: |
    cat default.out || true
    cat uc20.out || true
    cat run.out || true
    cat recovery.out || true

execute: |
    # does not outright fail
    snap debug boot-vars  > default.out

    if os.query is-core-ge 20; then
        echo "Check the boot-vars default output looks sane"
        # boot-vars default output is for the run mode bootloader, make sure its
        # output looks sane (though we don't expect any of the variables to be
        # set)
        MATCH 'kernel_status=$' < default.out

        snap debug boot-vars --uc20 > uc20.out
        snap debug boot-vars --root-dir /run/mnt/ubuntu-boot > run.out
        # the no-parameters output and explicit --uc20 should be the same
        diff -up default.out uc20.out
        # default shows a run mode bootloader variables, so the output shall be
        # identical again
        diff -up default.out run.out

        # try the recovery bootloader now
        snap debug boot-vars --root-dir /run/mnt/ubuntu-seed > recovery.out
        MATCH 'snapd_recovery_mode=run' < recovery.out
    else
        MATCH "snap_core=$(snaps.name core)_.*\.snap" < default.out
        MATCH "snap_kernel=$(snaps.name kernel)_.*\.snap" < default.out
        # relevant snaps are not being updated, so snap_mode is unset
        MATCH 'snap_mode=$' < default.out
    fi
