#!/bin/sh
# In-container orchestrator. Called by ./test from outside.
#   /work/test-rig/run.sh unit|e2e|all
#
# Expects to run inside the scrcpy-android-test docker image with
# /work mounted at the project root.

set -eu

cmd="${1:-unit}"

mkdir -p /work/.tools/home /work/.tools/gradle-home /work/.tools/avd
export HOME="/work/.tools/home"
export GRADLE_USER_HOME="/work/.tools/gradle-home"
export ANDROID_AVD_HOME="/work/.tools/avd"

unit() {
    echo "test: gradle :app:test"
    /work/gradlew --no-daemon -q :app:test
}

e2e() {
    /work/test-rig/e2e.sh
}

case "$cmd" in
    unit)   unit ;;
    e2e)    e2e ;;
    all)    unit && e2e ;;
    record) /work/test-rig/record.sh ;;
    apk)    /work/test-rig/build-apk.sh ;;
    *)      echo "run.sh: bad cmd $cmd" >&2; exit 2 ;;
esac
