#!/bin/bash
# Verify basic bootc functionality.
## kola:
##   timeoutMin: 30
##   tags: "needs-internet"
#
# Copyright (C) 2022 Red Hat, Inc.

set -xeuo pipefail

cd $(mktemp -d)

case "${AUTOPKGTEST_REBOOT_MARK:-}" in
  "")
    bootc status > status.txt
    grep 'Version:' status.txt
    bootc status --json > status.json
    image=$(jq -r '.status.booted.image.image' < status.json)
    echo "booted into $image"
    echo "ok status test"

    test "null" = $(jq '.status.staged' < status.json)
    # Should be a no-op
    bootc update
    test "null" = $(jq '.status.staged' < status.json)

    test '!' -w /usr
    bootc usroverlay
    test -w /usr
    echo "ok usroverlay"
    ;;
  *) echo "unexpected mark: ${AUTOPKGTEST_REBOOT_MARK}"; exit 1;;
esac
