diff --git a/test/entrypoint/should_retry_configuring/config.sh b/test/entrypoint/should_retry_configuring/config.sh index 49db04b8..bd18f4fd 100755 --- a/test/entrypoint/should_retry_configuring/config.sh +++ b/test/entrypoint/should_retry_configuring/config.sh @@ -20,6 +20,7 @@ error(){ 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"` diff --git a/test/entrypoint/should_switch_to_ephemeral_upstream_feature/config.sh b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/config.sh new file mode 100755 index 00000000..12f1e0bb --- /dev/null +++ b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/config.sh @@ -0,0 +1,29 @@ +#!/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 + diff --git a/test/entrypoint/should_switch_to_ephemeral_upstream_feature/runsvc.sh b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/runsvc.sh new file mode 100755 index 00000000..fa766433 --- /dev/null +++ b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/runsvc.sh @@ -0,0 +1,31 @@ +#!/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 "" + + diff --git a/test/entrypoint/should_switch_to_ephemeral_upstream_feature/test.sh b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/test.sh new file mode 100755 index 00000000..86f92531 --- /dev/null +++ b/test/entrypoint/should_switch_to_ephemeral_upstream_feature/test.sh @@ -0,0 +1,81 @@ +#!/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" diff --git a/test/entrypoint/should_work_non_ephemeral/config.sh b/test/entrypoint/should_work_non_ephemeral/config.sh index 200874d6..12f1e0bb 100755 --- a/test/entrypoint/should_work_non_ephemeral/config.sh +++ b/test/entrypoint/should_work_non_ephemeral/config.sh @@ -19,6 +19,7 @@ error(){ 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 diff --git a/test/entrypoint/should_work_normally/config.sh b/test/entrypoint/should_work_normally/config.sh index f1e7a7bf..1065f616 100755 --- a/test/entrypoint/should_work_normally/config.sh +++ b/test/entrypoint/should_work_normally/config.sh @@ -19,6 +19,7 @@ error(){ 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 diff --git a/test/entrypoint/should_work_normally/test.sh b/test/entrypoint/should_work_normally/test.sh index 5b7bfb3f..4ef1762b 100755 --- a/test/entrypoint/should_work_normally/test.sh +++ b/test/entrypoint/should_work_normally/test.sh @@ -55,9 +55,15 @@ if [ ${count} != "1" ]; then error "The configuration step was not run exactly once" exit 1 fi - success "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" + exit 1 +fi + log "Testing if runsvc ran" if [ ! -f "${RUNNER_HOME}/runsvc_ran" ]; then error "=============================="