Files
actions-runner-controller/test/startup/should_work_normally/test.sh
T

88 lines
2.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2021-08-02 10:11:48 +01:00
# UNITTEST: should work normally
# Will simulate a normal execution scenario. expects:
# - the configuration step to be run exactly once
# - the startup script to exit with no error
# - the run.sh script to run with the --once flag activated.
2021-08-02 10:11:48 +01:00
source ../assets/logging.sh
2021-08-02 10:11:48 +01:00
startup_log() {
2021-08-02 10:11:48 +01:00
while read I; do
printf "\startup.sh: $I\n"
2021-08-02 10:11:48 +01:00
done
}
log "Setting up test area"
export RUNNER_HOME=testarea
mkdir -p ${RUNNER_HOME}
2021-08-02 10:11:48 +01:00
log "Setting up the test"
export UNITTEST=true
export RUNNER_NAME="example_runner_name"
export RUNNER_REPO="myorg/myrepo"
export RUNNER_TOKEN="xxxxxxxxxxxxx"
# 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
2021-08-02 10:11:48 +01:00
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
2021-08-02 10:11:48 +01:00
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
log "Running the startup script"
2021-08-02 10:11:48 +01:00
log ""
# Run the runner startup script which as a final step runs this
# unit tests run.sh as it was symlinked
../../../runner/startup.sh 2> >(startup_log)
2021-08-02 10:11:48 +01:00
if [ "$?" != "0" ]; then
error "=========================="
error "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"
2021-08-02 10:11:48 +01:00
exit 1
fi
success "PASS | The configuration ran ${count} time(s)"
2021-08-02 10:11:48 +01:00
2021-09-13 10:58:15 +01:00
log "Testing if the configuration included the --ephemeral flag"
if grep -q -- '--ephemeral' ${RUNNER_HOME}/runner_config; then
error "==============================================="
error "FAIL | The configuration should not include the --ephemeral flag"
2021-09-13 10:58:15 +01:00
exit 1
fi
success "PASS | The --ephemeral switch was included in the configuration"
log "Testing if run.sh ran"
if [ ! -f "${RUNNER_HOME}/run_sh_ran" ]; then
2021-08-02 10:11:48 +01:00
error "=============================="
error "FAIL | The runner service has not run"
2021-08-02 10:11:48 +01:00
exit 1
fi
success "PASS | run.sh ran"
2021-08-02 10:11:48 +01:00
success ""
success "==========================="
success "Test completed successfully"