mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-11 03:57:01 +00:00
* feat: move to new run.sh container friendly file (#1244)
* fix: unit tests were very broken Co-authored-by: toast-gear <toast-gear@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
@@ -18,11 +18,15 @@ error(){
|
||||
}
|
||||
|
||||
success "I'm configured normally"
|
||||
touch .runner
|
||||
echo "$*" > runner_config
|
||||
|
||||
# Condition for should_retry_configuring test
|
||||
if [ -z "${FAIL_RUNNER_CONFIG_SETUP}" ]; then
|
||||
touch .runner
|
||||
fi
|
||||
|
||||
echo "$@" > runner_config
|
||||
success "created a dummy config file"
|
||||
success
|
||||
# Adding a counter to see how many times we've gone through the configuration step
|
||||
# adding a counter to see how many times we've gone through the configuration step
|
||||
count=`cat counter 2>/dev/null|| echo "0"`
|
||||
count=$((count + 1))
|
||||
echo ${count} > counter
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -20,12 +20,9 @@ error(){
|
||||
exit 1
|
||||
}
|
||||
|
||||
log "Dumping set runner arguments"
|
||||
echo "$@" > runner_args
|
||||
success "Pretending to run service..."
|
||||
touch run_sh_ran
|
||||
success "Success"
|
||||
success ""
|
||||
success "Running the service..."
|
||||
# SHOULD NOT HAPPEN
|
||||
# creating a file to show this script has run
|
||||
touch runsvc_ran
|
||||
success "...successful"
|
||||
success ""
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "$*" > runner_config
|
||||
success "I'm pretending the configuration is not successful"
|
||||
# increasing a counter to measure how many times we restarted
|
||||
count=`cat counter 2>/dev/null|| echo "0"`
|
||||
count=$((count + 1))
|
||||
echo ${count} > counter
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# UNITTEST: retry config
|
||||
# Will simulate a configuration failure and expects:
|
||||
# - the configuration step to be run 10 times
|
||||
# - the entrypoint script to exit with error code 2
|
||||
# - the runsvc.sh script to never run.
|
||||
# - the run.sh script to never run.
|
||||
|
||||
source ../logging.sh
|
||||
source ../assets/logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
@@ -14,17 +14,22 @@ entrypoint_log() {
|
||||
done
|
||||
}
|
||||
|
||||
log "Setting up the test"
|
||||
log "Setting up test area"
|
||||
export RUNNER_HOME=testarea
|
||||
mkdir -p ${RUNNER_HOME}
|
||||
|
||||
log "Setting up the test config"
|
||||
export UNITTEST=true
|
||||
export RUNNER_HOME=localhome
|
||||
export FAIL_RUNNER_CONFIG_SETUP=true
|
||||
export RUNNER_NAME="example_runner_name"
|
||||
export RUNNER_REPO="myorg/myrepo"
|
||||
export RUNNER_TOKEN="xxxxxxxxxxxxx"
|
||||
|
||||
mkdir -p ${RUNNER_HOME}/bin
|
||||
# add up the config.sh and runsvc.sh
|
||||
ln -s ../config.sh ${RUNNER_HOME}/config.sh
|
||||
ln -s ../../runsvc.sh ${RUNNER_HOME}/bin/runsvc.sh
|
||||
# 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}
|
||||
@@ -33,41 +38,44 @@ cleanup() {
|
||||
unset RUNNER_NAME
|
||||
unset RUNNER_REPO
|
||||
unset RUNNER_TOKEN
|
||||
unset FAIL_RUNNER_CONFIG_SETUP
|
||||
}
|
||||
|
||||
# Always run cleanup when test ends regardless of how it ends
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
# Run the runner entrypoint script which as a final step runs this
|
||||
# unit tests run.sh as it was symlinked
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "2" ]; then
|
||||
error "========================================="
|
||||
error "Configuration should have thrown an error"
|
||||
error "FAIL | Configuration should have thrown an error"
|
||||
exit 1
|
||||
fi
|
||||
success "Entrypoint didn't complete successfully"
|
||||
success ""
|
||||
|
||||
success "PASS | Entrypoint didn't complete successfully"
|
||||
|
||||
log "Checking the counter, should have 10 iterations"
|
||||
count=`cat ${RUNNER_HOME}/counter || "notfound"`
|
||||
if [ "${count}" != "10" ]; then
|
||||
error "============================================="
|
||||
error "The retry loop should have done 10 iterations"
|
||||
error "FAIL | The retry loop should have done 10 iterations"
|
||||
exit 1
|
||||
fi
|
||||
success "Retry loop went up to 10"
|
||||
success
|
||||
success "PASS | Retry loop went up to 10"
|
||||
|
||||
log "Checking that runsvc never ran"
|
||||
if [ -f ${RUNNER_HOME}/runsvc_ran ]; then
|
||||
log "Checking that run.sh never ran"
|
||||
if [ -f ${RUNNER_HOME}/run_sh_ran ]; then
|
||||
error "================================================================="
|
||||
error "runsvc was invoked, entrypoint.sh should have failed before that."
|
||||
error "FAIL | run.sh was invoked, entrypoint.sh should have failed before that."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "runsvc.sh never ran"
|
||||
success "PASS | run.sh never ran"
|
||||
success
|
||||
success "==========================="
|
||||
success "Test completed successfully"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success "I'm configured normally"
|
||||
touch .runner
|
||||
echo "$*" > runner_config
|
||||
success "created a dummy config file"
|
||||
success
|
||||
# adding a counter to see how many times we've gone through a configuration step
|
||||
count=`cat counter 2>/dev/null|| echo "0"`
|
||||
count=$((count + 1))
|
||||
echo ${count} > counter
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
exit 1
|
||||
}
|
||||
|
||||
success ""
|
||||
success "Running the service..."
|
||||
# test if --once is present as a parameter
|
||||
echo "$*" | grep -q 'once' && error "Should not include --once in the parameters"
|
||||
success "...successful"
|
||||
touch runsvc_ran
|
||||
success ""
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# UNITTEST: should work as non ephemeral
|
||||
# Will simulate a scenario where ephemeral=false. expects:
|
||||
# - the configuration step to be run exactly once
|
||||
# - the entrypoint script to exit with no error
|
||||
# - the runsvc.sh script to run without the --once flag
|
||||
|
||||
source ../logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
printf "\tentrypoint.sh: $I\n"
|
||||
done
|
||||
}
|
||||
|
||||
log "Setting up the test"
|
||||
export UNITTEST=true
|
||||
export RUNNER_HOME=localhome
|
||||
export RUNNER_NAME="example_runner_name"
|
||||
export RUNNER_REPO="myorg/myrepo"
|
||||
export RUNNER_TOKEN="xxxxxxxxxxxxx"
|
||||
export RUNNER_EPHEMERAL=true
|
||||
export RUNNER_FEATURE_FLAG_EPHEMERAL=true
|
||||
|
||||
mkdir -p ${RUNNER_HOME}/bin
|
||||
# add up the config.sh and runsvc.sh
|
||||
ln -s ../config.sh ${RUNNER_HOME}/config.sh
|
||||
ln -s ../../runsvc.sh ${RUNNER_HOME}/bin/runsvc.sh
|
||||
|
||||
cleanup() {
|
||||
rm -rf ${RUNNER_HOME}
|
||||
unset UNITTEST
|
||||
unset RUNNERHOME
|
||||
unset RUNNER_NAME
|
||||
unset RUNNER_REPO
|
||||
unset RUNNER_TOKEN
|
||||
unset RUNNER_EPHEMERAL
|
||||
unset RUNNER_FEATURE_FLAG_EPHEMERAL
|
||||
}
|
||||
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
error "==========================================="
|
||||
error "Entrypoint script did not exit successfully"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Testing if we went through the configuration step only once"
|
||||
count=`cat ${RUNNER_HOME}/counter || echo "not_found"`
|
||||
if [ ${count} != "1" ]; then
|
||||
error "==============================================="
|
||||
error "The configuration step was not run exactly once"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Testing if the configuration included the --ephemeral flag"
|
||||
if ! grep -q -- '--ephemeral' ${RUNNER_HOME}/runner_config; then
|
||||
error "==============================================="
|
||||
error "The configuration did not include the --ephemeral flag"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "The configuration ran ${count} time(s)"
|
||||
|
||||
log "Testing if runsvc ran"
|
||||
if [ ! -f "${RUNNER_HOME}/runsvc_ran" ]; then
|
||||
error "=============================="
|
||||
error "The runner service has not run"
|
||||
exit 1
|
||||
fi
|
||||
success "The service ran"
|
||||
success ""
|
||||
success "==========================="
|
||||
success "Test completed successfully"
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
exit 1
|
||||
}
|
||||
|
||||
success ""
|
||||
success "Running the service..."
|
||||
# test if --once is present as a parameter
|
||||
echo "$*" | grep -q 'once' || error "Should include --once in the parameters"j
|
||||
success "...successful"
|
||||
touch runsvc_ran
|
||||
success ""
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success "I'm configured normally"
|
||||
touch .runner
|
||||
echo "$*" > runner_config
|
||||
success "created a dummy config file"
|
||||
success
|
||||
# adding a counter to see how many times we've gone through a configuration step
|
||||
count=`cat counter 2>/dev/null|| echo "0"`
|
||||
count=$((count + 1))
|
||||
echo ${count} > counter
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
exit 1
|
||||
}
|
||||
|
||||
success ""
|
||||
success "Running the service..."
|
||||
# test if --once is present as a parameter
|
||||
echo "$*" | grep -q 'once' && error "Should not include --once in the parameters"
|
||||
success "...successful"
|
||||
touch runsvc_ran
|
||||
success ""
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# UNITTEST: should work as non ephemeral
|
||||
# Will simulate a scenario where ephemeral=false. expects:
|
||||
# - the configuration step to be run exactly once
|
||||
# - the entrypoint script to exit with no error
|
||||
# - the runsvc.sh script to run without the --once flag
|
||||
# - the run.sh script to run without the --once flag
|
||||
|
||||
source ../logging.sh
|
||||
source ../assets/logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
@@ -14,18 +14,22 @@ entrypoint_log() {
|
||||
done
|
||||
}
|
||||
|
||||
log "Setting up test area"
|
||||
export RUNNER_HOME=testarea
|
||||
mkdir -p ${RUNNER_HOME}
|
||||
|
||||
log "Setting up the test"
|
||||
export UNITTEST=true
|
||||
export RUNNER_HOME=localhome
|
||||
export RUNNER_NAME="example_runner_name"
|
||||
export RUNNER_REPO="myorg/myrepo"
|
||||
export RUNNER_TOKEN="xxxxxxxxxxxxx"
|
||||
export RUNNER_EPHEMERAL=false
|
||||
|
||||
mkdir -p ${RUNNER_HOME}/bin
|
||||
# add up the config.sh and runsvc.sh
|
||||
ln -s ../config.sh ${RUNNER_HOME}/config.sh
|
||||
ln -s ../../runsvc.sh ${RUNNER_HOME}/bin/runsvc.sh
|
||||
# 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}
|
||||
@@ -37,16 +41,19 @@ cleanup() {
|
||||
unset RUNNER_EPHEMERAL
|
||||
}
|
||||
|
||||
# Always run cleanup when test ends regardless of how it ends
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
# Run the runner entrypoint script which as a final step runs this
|
||||
# unit tests run.sh as it was symlinked
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
error "==========================================="
|
||||
error "Entrypoint script did not exit successfully"
|
||||
error "FAIL | Entrypoint script did not exit successfully"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -54,19 +61,19 @@ log "Testing if we went through the configuration step only once"
|
||||
count=`cat ${RUNNER_HOME}/counter || echo "not_found"`
|
||||
if [ ${count} != "1" ]; then
|
||||
error "==============================================="
|
||||
error "The configuration step was not run exactly once"
|
||||
error "FAIL | The configuration step was not run exactly once"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "The configuration ran ${count} time(s)"
|
||||
success "PASS | The configuration ran ${count} time(s)"
|
||||
|
||||
log "Testing if runsvc ran"
|
||||
if [ ! -f "${RUNNER_HOME}/runsvc_ran" ]; then
|
||||
log "Testing if run.sh ran"
|
||||
if [ ! -f "${RUNNER_HOME}/run_sh_ran" ]; then
|
||||
error "=============================="
|
||||
error "The runner service has not run"
|
||||
error "FAIL | The runner service has not run"
|
||||
exit 1
|
||||
fi
|
||||
success "The service ran"
|
||||
success "PASS | run.sh ran"
|
||||
success ""
|
||||
success "==========================="
|
||||
success "Test completed successfully"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success "I'm configured normally"
|
||||
touch .runner
|
||||
echo "$*" > runner_config
|
||||
success "created a dummy config file"
|
||||
success
|
||||
# Adding a counter to see how many times we've gone through the configuration step
|
||||
count=`cat counter 2>/dev/null|| echo "0"`
|
||||
count=$((count + 1))
|
||||
echo ${count} > counter
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export LIGHTGREEN='\e[0;32m'
|
||||
export LIGHTRED='\e[0;31m'
|
||||
export WHITE='\e[0;97m'
|
||||
export RESET='\e[0m'
|
||||
|
||||
log(){
|
||||
printf "\t${WHITE}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
success(){
|
||||
printf "\t${LIGHTGREEN}$@${RESET}\n" 2>&1
|
||||
}
|
||||
|
||||
error(){
|
||||
printf "\t${LIGHTRED}$@${RESET}\n" 2>&1
|
||||
exit 1
|
||||
}
|
||||
|
||||
success ""
|
||||
success "Running the service..."
|
||||
# test if --once is present as a parameter
|
||||
echo "$*" | grep -q 'once' || error "Should include --once in the parameters"j
|
||||
success "...successful"
|
||||
touch runsvc_ran
|
||||
success ""
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# UNITTEST: should work normally
|
||||
# Will simulate a normal execution scenario. expects:
|
||||
# - the configuration step to be run exactly once
|
||||
# - the entrypoint script to exit with no error
|
||||
# - the runsvc.sh script to run with the --once flag activated.
|
||||
# - the run.sh script to run with the --once flag activated.
|
||||
|
||||
source ../logging.sh
|
||||
source ../assets/logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
@@ -14,17 +14,21 @@ entrypoint_log() {
|
||||
done
|
||||
}
|
||||
|
||||
log "Setting up test area"
|
||||
export RUNNER_HOME=testarea
|
||||
mkdir -p ${RUNNER_HOME}
|
||||
|
||||
log "Setting up the test"
|
||||
export UNITTEST=true
|
||||
export RUNNER_HOME=localhome
|
||||
export RUNNER_NAME="example_runner_name"
|
||||
export RUNNER_REPO="myorg/myrepo"
|
||||
export RUNNER_TOKEN="xxxxxxxxxxxxx"
|
||||
|
||||
mkdir -p ${RUNNER_HOME}/bin
|
||||
# add up the config.sh and runsvc.sh
|
||||
ln -s ../config.sh ${RUNNER_HOME}/config.sh
|
||||
ln -s ../../runsvc.sh ${RUNNER_HOME}/bin/runsvc.sh
|
||||
# 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}
|
||||
@@ -35,11 +39,14 @@ cleanup() {
|
||||
unset RUNNER_TOKEN
|
||||
}
|
||||
|
||||
# Always run cleanup when test ends regardless of how it ends
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
# Run the runner entrypoint script which as a final step runs this
|
||||
# unit tests run.sh as it was symlinked
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
@@ -52,26 +59,29 @@ log "Testing if the configuration step was run only once"
|
||||
count=`cat ${RUNNER_HOME}/counter || echo "not_found"`
|
||||
if [ ${count} != "1" ]; then
|
||||
error "==============================================="
|
||||
error "The configuration step was not run exactly once"
|
||||
error "FAIL | The configuration step was not run exactly once"
|
||||
exit 1
|
||||
fi
|
||||
success "The configuration ran ${count} time(s)"
|
||||
|
||||
success "PASS | The configuration ran ${count} time(s)"
|
||||
|
||||
log "Testing if the configuration included the --ephemeral flag"
|
||||
if grep -q -- '--ephemeral' ${RUNNER_HOME}/runner_config; then
|
||||
error "==============================================="
|
||||
error "The configuration should not include the --ephemeral flag"
|
||||
error "FAIL | The configuration should not include the --ephemeral flag"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Testing if runsvc ran"
|
||||
if [ ! -f "${RUNNER_HOME}/runsvc_ran" ]; then
|
||||
success "PASS | The --ephemeral switch was included in the configuration"
|
||||
|
||||
log "Testing if run.sh ran"
|
||||
if [ ! -f "${RUNNER_HOME}/run_sh_ran" ]; then
|
||||
error "=============================="
|
||||
error "The runner service has not run"
|
||||
error "FAIL | The runner service has not run"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "The service ran"
|
||||
success "PASS | run.sh ran"
|
||||
success ""
|
||||
success "==========================="
|
||||
success "Test completed successfully"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# UNITTEST: should work disable update
|
||||
# Will simulate a scneario where disableupdate=true. expects:
|
||||
@@ -6,7 +6,7 @@
|
||||
# - the entrypoint script to exit with no error
|
||||
# - the config.sh script to run with the --disableupdate flag set to 'true'.
|
||||
|
||||
source ../logging.sh
|
||||
source ../assets/logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
@@ -14,18 +14,22 @@ entrypoint_log() {
|
||||
done
|
||||
}
|
||||
|
||||
log "Setting up test area"
|
||||
export RUNNER_HOME=testarea
|
||||
mkdir -p ${RUNNER_HOME}
|
||||
|
||||
log "Setting up the test"
|
||||
export UNITTEST=true
|
||||
export RUNNER_HOME=localhome
|
||||
export RUNNER_NAME="example_runner_name"
|
||||
export RUNNER_REPO="myorg/myrepo"
|
||||
export RUNNER_TOKEN="xxxxxxxxxxxxx"
|
||||
export DISABLE_RUNNER_UPDATE="true"
|
||||
|
||||
mkdir -p ${RUNNER_HOME}/bin
|
||||
# add up the config.sh and runsvc.sh
|
||||
ln -s ../config.sh ${RUNNER_HOME}/config.sh
|
||||
ln -s ../../runsvc.sh ${RUNNER_HOME}/bin/runsvc.sh
|
||||
# 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}
|
||||
@@ -36,16 +40,19 @@ cleanup() {
|
||||
unset RUNNER_TOKEN
|
||||
}
|
||||
|
||||
# Always run cleanup when test ends regardless of how it ends
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
# 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
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
error "=========================="
|
||||
error "Test completed with errors"
|
||||
error "FAIL | Test completed with errors"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -53,26 +60,28 @@ log "Testing if the configuration step was run only once"
|
||||
count=`cat ${RUNNER_HOME}/counter || echo "not_found"`
|
||||
if [ ${count} != "1" ]; then
|
||||
error "==============================================="
|
||||
error "The configuration step was not run exactly once"
|
||||
error "FAIL | The configuration step was not run exactly once"
|
||||
exit 1
|
||||
fi
|
||||
success "The configuration ran ${count} time(s)"
|
||||
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 "The configuration should not include the --disableupdate flag"
|
||||
error "FAIL | The configuration should not include the --disableupdate flag"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Testing if runsvc ran"
|
||||
if [ ! -f "${RUNNER_HOME}/runsvc_ran" ]; then
|
||||
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 "The runner service has not run"
|
||||
error "FAIL | The runner service has not run"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "The service ran"
|
||||
success "PASS | run.sh ran"
|
||||
success ""
|
||||
success "==========================="
|
||||
success "Test completed successfully"
|
||||
90
test/entrypoint/should_work_use_once_switch/test.sh
Executable file
90
test/entrypoint/should_work_use_once_switch/test.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# UNITTEST: should work legacy once switch set
|
||||
# Will simulate a scenario where RUNNER_FEATURE_FLAG_EPHEMERAL=false. expects:
|
||||
# - the configuration step to be run exactly once
|
||||
# - the entrypoint script to exit with no error
|
||||
# - the run.sh script to run with the --once flag
|
||||
|
||||
source ../assets/logging.sh
|
||||
|
||||
entrypoint_log() {
|
||||
while read I; do
|
||||
printf "\tentrypoint.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 RUNNER_FEATURE_FLAG_EPHEMERAL="false"
|
||||
export RUNNER_EPHEMERAL="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
|
||||
unset RUNNER_EPHEMERAL
|
||||
unset RUNNER_FEATURE_FLAG_EPHEMERAL
|
||||
}
|
||||
|
||||
# Always run cleanup when test ends regardless of how it ends
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
log "Running the entrypoint"
|
||||
log ""
|
||||
|
||||
# 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
|
||||
../../../runner/entrypoint.sh 2> >(entrypoint_log)
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
error "==========================================="
|
||||
error "FAIL | Entrypoint script did not exit successfully"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Testing if we went through the configuration step 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 --once flag"
|
||||
if ! grep -q -- '--once' ${RUNNER_HOME}/runner_args; then
|
||||
error "==============================================="
|
||||
error "FAIL | The configuration did not include the --once flag, config printed below:"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "PASS | The --once argument was passed in"
|
||||
|
||||
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"
|
||||
@@ -1,13 +1,12 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source logging.sh
|
||||
source assets/logging.sh
|
||||
|
||||
for unittest in ./should*; do
|
||||
log "**********************************"
|
||||
log " UNIT TEST: ${unittest}"
|
||||
log "**********************************"
|
||||
log ""
|
||||
|
||||
cd ${unittest}
|
||||
./test.sh
|
||||
ret_code=$?
|
||||
Reference in New Issue
Block a user