diff --git a/Makefile b/Makefile index cbec0220..4b7a18c8 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ REC_DIRS := cmd ########## Test Settings ########## E2E_LOG_LEVEL ?= WARN E2E_SKIP ?= +E2E_EXTRA ?= E2E_RUNNER_START_TIMEOUT ?= 10 ########## Go Build Options ########## @@ -152,7 +153,7 @@ check: check-fmt lint e2e: build-docker-dind @echo "Running e2e tests in k3d:$(K3D_IMAGE_TAG)" - LOG_LEVEL="$(E2E_LOG_LEVEL)" E2E_SKIP="$(E2E_SKIP)" E2E_RUNNER_START_TIMEOUT=$(E2E_RUNNER_START_TIMEOUT) tests/dind.sh "${K3D_IMAGE_TAG}-dind" + LOG_LEVEL="$(E2E_LOG_LEVEL)" E2E_SKIP="$(E2E_SKIP)" E2E_EXTRA="$(E2E_EXTRA)" E2E_RUNNER_START_TIMEOUT=$(E2E_RUNNER_START_TIMEOUT) tests/dind.sh "${K3D_IMAGE_TAG}-dind" ci-tests: fmt check e2e diff --git a/tests/common.sh b/tests/common.sh index f8c0d840..08d4edca 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -51,6 +51,13 @@ passed() { fi } +section() { + title_length=$((${#1}+4)) + log "$(printf "${CYA}#%.0s${END}" $(eval "echo {1.."$(($title_length))"}"); printf "\n";)" + log "$(printf "${CYA}#${END} %s ${CYA}#${END}\n" "$1")" + log "$(printf "${CYA}#%.0s${END}" $(eval "echo {1.."$(($title_length))"}"); printf "\n";)" +} + # checks that a URL is available, with an optional error message check_url() { command_exists curl || abort "curl is not installed" diff --git a/tests/dind.sh b/tests/dind.sh index 52a4d898..c0525e7f 100755 --- a/tests/dind.sh +++ b/tests/dind.sh @@ -20,6 +20,7 @@ k3de2e=$(docker run -d \ -e CI="true" \ -e LOG_LEVEL="$LOG_LEVEL" \ -e E2E_SKIP="$E2E_SKIP" \ + -e E2E_EXTRA="$E2E_EXTRA" \ --name "k3d-e2e-runner-$TIMESTAMP" \ "k3d:$K3D_IMAGE_TAG") diff --git a/tests/extra_test_k3s_versions.sh b/tests/extra_test_k3s_versions.sh new file mode 100755 index 00000000..e9c8e93f --- /dev/null +++ b/tests/extra_test_k3s_versions.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +[ -d "$CURR_DIR" ] || { echo "FATAL: no current dir (maybe running in zsh?)"; exit 1; } + +K3S_VERSIONS=("v1.17.12-k3s1" "v1.18.9-k3s1" "v1.19.1-k3s1") + +# shellcheck source=./common.sh +source "$CURR_DIR/common.sh" + +for version in "${K3S_VERSIONS[@]}"; do + + info "Creating a cluster with k3s version $version ..." + $EXE cluster create c1 --wait --timeout 60s --api-port 6443 --image "rancher/k3s:$version" || failed "could not create cluster with k3s version $version" + + info "Checking we have access to the cluster ..." + check_clusters "c1" || failed "error checking cluster with k3s version $version" + + info "Deleting cluster ..." + $EXE cluster delete c1 || failed "could not delete the cluster c1" + + K3S_IMAGE_TAG="$version" $CURR_DIR/test_multi_master.sh + +done + +exit 0 + + diff --git a/tests/runner.sh b/tests/runner.sh index 16ebf1ee..5177cf1f 100755 --- a/tests/runner.sh +++ b/tests/runner.sh @@ -4,6 +4,7 @@ CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" [ -d "$CURR_DIR" ] || { echo "FATAL: no current dir (maybe running in zsh?)"; exit 1; } : "${E2E_SKIP:=""}" +: "${E2E_EXTRA:=""}" # shellcheck source=./common.sh source "$CURR_DIR/common.sh" @@ -16,15 +17,32 @@ info "Preparing filesystem and environment..." mkdir -p $HOME/.kube +section "BASIC TESTS" + for i in $CURR_DIR/test_*.sh ; do - base=$(basename $i .sh) + base=$(basename "$i" .sh) if [[ $E2E_SKIP =~ (^| )$base($| ) ]]; then highlight "***** Skipping $base *****" else highlight "***** Running $base *****" - $i || abort "test $base failed" + "$i" || abort "test $base failed" fi done +if [[ -n "$E2E_EXTRA" ]]; then + section "EXTRA TESTS" + for i in $CURR_DIR/extra_test_*.sh ; do + base=$(basename "$i" .sh) + if [[ $E2E_SKIP =~ (^| )$base($| ) ]]; then + highlight "***** Skipping $base *****" + else + highlight "***** Running $base *****" + "$i" || abort "test $base failed" + fi + done +else + info "NOT running EXTRA tests, please set E2E_EXTRA=1 if you wish to do so" +fi + exit 0 diff --git a/tests/test_multi_master.sh b/tests/test_multi_master.sh index 39f28a44..d9497554 100755 --- a/tests/test_multi_master.sh +++ b/tests/test_multi_master.sh @@ -6,9 +6,16 @@ CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # shellcheck source=./common.sh source "$CURR_DIR/common.sh" -info "Creating cluster multiserver..." -$EXE cluster create "multiserver" --servers 3 --api-port 6443 --wait --timeout 360s || failed "could not create cluster multiserver" +: "${EXTRA_FLAG:=""}" +: "${EXTRA_TITLE:=""}" +if [[ -n "$K3S_IMAGE_TAG" ]]; then + EXTRA_FLAG="--image rancher/k3s:$K3S_IMAGE_TAG" + EXTRA_TITLE="(rancher/k3s:$K3S_IMAGE_TAG)" +fi + +info "Creating cluster multiserver $EXTRA_TITLE ..." +$EXE cluster create "multiserver" --servers 3 --api-port 6443 --wait --timeout 360s $EXTRA_FLAG || failed "could not create cluster multiserver" info "Checking that we have access to the cluster..." check_clusters "multiserver" || failed "error checking cluster"