Fix runner startup.sh tests

- `should_work_use_disable_once_switch` was failing since the support for --once has been removed a while ago. Removed the test.
- Added `cd` before running `startup.sh` for access to the logger.sh library from within the script
- Included the runner directory into `$PATH` for access to `update-status` from within the script
This commit is contained in:
Yusuke Kuoka 2023-05-31 01:30:37 +00:00
parent 8a8f28f12d
commit fb1a7cce8b
4 changed files with 12 additions and 93 deletions

View File

@ -15,7 +15,7 @@ startup_log() {
} }
log "Setting up test area" log "Setting up test area"
export RUNNER_HOME=testarea export RUNNER_HOME=$(pwd)/testarea
mkdir -p ${RUNNER_HOME} mkdir -p ${RUNNER_HOME}
log "Setting up the test config" log "Setting up the test config"
@ -49,7 +49,9 @@ log ""
# Run the runner startup script which as a final step runs this # Run the runner startup script which as a final step runs this
# unit tests run.sh as it was symlinked # unit tests run.sh as it was symlinked
../../../runner/startup.sh 2> >(startup_log) cd ../../../runner
export PATH=${PATH}:$(pwd)
./startup.sh 2> >(startup_log)
if [ "$?" != "2" ]; then if [ "$?" != "2" ]; then
error "=========================================" error "========================================="

View File

@ -15,7 +15,7 @@ startup_log() {
} }
log "Setting up test area" log "Setting up test area"
export RUNNER_HOME=testarea export RUNNER_HOME=$(pwd)/testarea
mkdir -p ${RUNNER_HOME} mkdir -p ${RUNNER_HOME}
log "Setting up the test" log "Setting up the test"
@ -49,7 +49,9 @@ log ""
# Run the runner entrypstartupoint script which as a final step runs this # Run the runner entrypstartupoint script which as a final step runs this
# unit tests run.sh as it was symlinked # unit tests run.sh as it was symlinked
../../../runner/startup.sh 2> >(startup_log) cd ../../../runner
export PATH=${PATH}:$(pwd)
./startup.sh 2> >(startup_log)
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
error "===========================================" error "==========================================="

View File

@ -15,7 +15,7 @@ startup_log() {
} }
log "Setting up test area" log "Setting up test area"
export RUNNER_HOME=testarea export RUNNER_HOME=$(pwd)/testarea
mkdir -p ${RUNNER_HOME} mkdir -p ${RUNNER_HOME}
log "Setting up the test" log "Setting up the test"
@ -47,7 +47,9 @@ log ""
# Run the runner startup script which as a final step runs this # Run the runner startup script which as a final step runs this
# unit tests run.sh as it was symlinked # unit tests run.sh as it was symlinked
../../../runner/startup.sh 2> >(startup_log) cd ../../../runner
export PATH=${PATH}:$(pwd)
./startup.sh 2> >(startup_log)
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
error "==========================" error "=========================="

View File

@ -1,87 +0,0 @@
#!/usr/bin/env bash
# UNITTEST: should work disable update
# Will simulate a scneario where disableupdate=true. expects:
# - the configuration step to be run exactly once
# - the startup script to exit with no error
# - the config.sh script to run with the --disableupdate flag set to 'true'.
source ../assets/logging.sh
startup_log() {
while read I; do
printf "\tstartup.sh: $I\n"
done
}
log "Setting up test area"
export RUNNER_HOME=testarea
mkdir -p ${RUNNER_HOME}
log "Setting up the test"
export UNITTEST=true
export RUNNER_NAME="example_runner_name"
export RUNNER_REPO="myorg/myrepo"
export RUNNER_TOKEN="xxxxxxxxxxxxx"
export DISABLE_RUNNER_UPDATE="true"
# run.sh and config.sh get used by the runner's real entrypoint.sh and are part of actions/runner.
# We change symlink dummy versions so the entrypoint.sh can run allowing us to test the real entrypoint.sh
log "Symlink dummy config.sh and run.sh"
ln -s ../../assets/config.sh ${RUNNER_HOME}/config.sh
ln -s ../../assets/run.sh ${RUNNER_HOME}/run.sh
cleanup() {
rm -rf ${RUNNER_HOME}
unset UNITTEST
unset RUNNERHOME
unset RUNNER_NAME
unset RUNNER_REPO
unset RUNNER_TOKEN
}
# Always run cleanup when test ends regardless of how it ends
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
log "Running the startup script"
log ""
# run.sh and config.sh get used by the runner's real startup.sh and are part of actions/runner.
# We change symlink dummy versions so the startup.sh can run allowing us to test the real entrypoint.sh
../../../runner/startup.sh 2> >(startup_log)
if [ "$?" != "0" ]; then
error "=========================="
error "FAIL | Test completed with errors"
exit 1
fi
log "Testing if the configuration step was run only once"
count=`cat ${RUNNER_HOME}/counter || echo "not_found"`
if [ ${count} != "1" ]; then
error "==============================================="
error "FAIL | The configuration step was not run exactly once"
exit 1
fi
success "PASS | The configuration ran ${count} time(s)"
log "Testing if the configuration included the --disableupdate flag"
if ! grep -q -- '--disableupdate' ${RUNNER_HOME}/runner_config; then
error "==============================================="
error "FAIL | The configuration should not include the --disableupdate flag"
exit 1
fi
success "PASS | The --disableupdate switch was included in the configuration"
log "Testing if run.sh ran"
if [ ! -f "${RUNNER_HOME}/run_sh_ran" ]; then
error "=============================="
error "FAIL | The runner service has not run"
exit 1
fi
success "PASS | run.sh ran"
success ""
success "==========================="
success "Test completed successfully"