#!/bin/sh

# This is the expected entry point for Cockpit CI; will be called without
# arguments but with an appropriate $TEST_OS, and optionally $TEST_SCENARIO

set -eu

tools/make-bots

TEST_SCENARIO=${TEST_SCENARIO:-verify}
TEST_OS_DEFAULT=$(PYTHONPATH=bots python3 -c 'from machine.machine_core.constants import TEST_OS_DEFAULT; print(TEST_OS_DEFAULT)')

case $TEST_SCENARIO in
    verify|devel|firefox|firefox-devel)
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%devel}" ] || export NODE_ENV=development
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO##firefox}" ] || export TEST_BROWSER=firefox
        test/image-prepare --verbose $TEST_OS
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify
        ;;
    container-*)
        test/image-prepare --quick --containers --verbose $TEST_OS
        test/containers/run-tests --container ${TEST_SCENARIO#*-}
        ;;
    dnf-copr*)
        bots/image-customize -v --run-command 'dnf -y copr enable rpmsoftwaremanagement/dnf-nightly && dnf -y --setopt=install_weak_deps=False update' $TEST_OS
        test/image-prepare --verbose --overlay $TEST_OS
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify
        ;;
    *)
        echo "Unknown test scenario: $TEST_SCENARIO"
        exit 1
esac
