|
1 | 1 | #!/usr/bin/env bash
|
| 2 | +# |
| 3 | +# Run the integration test suite for this operator. |
| 4 | +# |
| 5 | +# If a "tests/release.yaml" file is present, it will install the operators listed |
| 6 | +# in the release file first. The name of the test suite in that file must be "tests". |
| 7 | +# Since each operator test suite has different dependencies, the "tests/release.yaml" |
| 8 | +# file is not included in this repository. |
| 9 | +# |
| 10 | +# Optionally you can provide a specific test suite to run and even a specific |
| 11 | +# test name. |
| 12 | +# |
| 13 | +# Example 1 - run all tests of the openshift suite. |
| 14 | +# |
| 15 | +# ./scripts/run_tests.sh --test-suite openshift --parallel 2 |
| 16 | +# |
| 17 | +# Example 2 - run all tests that contain the word "smoke" in the openshift suite and skip resource deletion. |
| 18 | +# |
| 19 | +# ./scripts/run_tests.sh \ |
| 20 | +# --test-suite openshift \ |
| 21 | +# --test smoke \ |
| 22 | +# --skip-delete |
| 23 | +# |
2 | 24 |
|
3 |
| -# Check if the test expansion tool beku is installed |
4 | 25 | set +e
|
5 |
| -which beku > /dev/null 2>&1 |
6 |
| -beku_installed=$? |
7 |
| -set -e |
8 |
| -if [ $beku_installed -ne 0 ]; then |
9 |
| - echo "Please install beku.py to run the tests, see https://github.com/stackabletech/beku.py" |
10 |
| - exit 1 |
11 |
| -fi |
12 |
| - |
13 |
| -echo "Using beku version: $(beku --version)" |
14 |
| - |
15 |
| -# cleanup any old tests |
16 |
| -rm -rf tests/_work |
17 |
| - |
18 |
| -# Expand the tests |
19 |
| -beku |
20 |
| - |
21 |
| -# Run tests, pass the params |
22 |
| -pushd tests/_work |
23 |
| -kubectl kuttl test "$@" |
24 |
| -popd |
| 26 | + |
| 27 | +DIR_NAME=$(dirname "$0") |
| 28 | +REPO_ROOT=$(dirname "$DIR_NAME") |
| 29 | +TEST_ROOT="$REPO_ROOT/tests/_work" |
| 30 | +RELEASE_FILE="$REPO_ROOT/tests/release.yaml" |
| 31 | +STACKABLECTL_SKIP_RELEASE="" |
| 32 | +BEKU_TEST_SUITE="" |
| 33 | +KUTTL_TEST="" |
| 34 | +KUTTL_SKIP_DELETE="" |
| 35 | +KUTTL_PARALLEL="" |
| 36 | + |
| 37 | +is_installed() { |
| 38 | + local command="$1" |
| 39 | + local install_url="$2" |
| 40 | + |
| 41 | + if ! which "$command" >/dev/null 2>&1; then |
| 42 | + echo "Command [$command] not found. To install it, please see $install_url" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +install_operators() { |
| 48 | + if [ -n "$STACKABLECTL_SKIP_RELEASE" ]; then |
| 49 | + echo "Skipping operator installation" |
| 50 | + return |
| 51 | + fi |
| 52 | + |
| 53 | + if [ -f "$RELEASE_FILE" ]; then |
| 54 | + echo "Installing operators with stackablectl version: $(stackablectl --version)" |
| 55 | + stackablectl release install --release-file "$RELEASE_FILE" tests |
| 56 | + else |
| 57 | + echo "No tests/release.yaml found, skipping operator installation" |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +expand_test_suite() { |
| 62 | + # Expand the tests |
| 63 | + echo "Running beku version: $(beku --version)" |
| 64 | + if [ -z "$BEKU_TEST_SUITE" ]; then |
| 65 | + echo "No test suite specified, expanding all tests" |
| 66 | + beku |
| 67 | + else |
| 68 | + echo "Expanding test suite: $BEKU_TEST_SUITE" |
| 69 | + beku --suite "$BEKU_TEST_SUITE" |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +run_tests() { |
| 74 | + echo "Running kuttl version: $(kubectl-kuttl --version)" |
| 75 | + |
| 76 | + local OPTS=("test") |
| 77 | + |
| 78 | + if [ -n "$KUTTL_SKIP_DELETE" ]; then |
| 79 | + OPTS+=("--skip-delete") |
| 80 | + fi |
| 81 | + |
| 82 | + if [ -n "$KUTTL_PARALLEL" ]; then |
| 83 | + OPTS+=("--parallel $KUTTL_PARALLEL") |
| 84 | + fi |
| 85 | + |
| 86 | + if [ -n "$KUTTL_TEST" ]; then |
| 87 | + OPTS+=("--test=$KUTTL_TEST") |
| 88 | + fi |
| 89 | + |
| 90 | + pushd "$TEST_ROOT" || exit |
| 91 | + kubectl-kuttl "${OPTS[*]}" |
| 92 | + popd || exit |
| 93 | +} |
| 94 | + |
| 95 | +usage() { |
| 96 | + cat <<USAGE |
| 97 | + Usage: |
| 98 | + run_tests.sh [options] |
| 99 | + Options: |
| 100 | + --test-suite <test-suite> Run a test suite from the test_definition.yaml file. Default is all tests. |
| 101 | + --test <test-name> Run a specific test or a set of tests. |
| 102 | + --skip-delete Skip resource deletion after the test run. |
| 103 | + --parallel <number> Run tests in parallel. Default is to run all tests in parallel. |
| 104 | + --skip-release Skip the operator installation. |
| 105 | +USAGE |
| 106 | +} |
| 107 | + |
| 108 | +parse_args() { |
| 109 | + while [[ "$#" -gt 0 ]]; do |
| 110 | + case $1 in |
| 111 | + --skip-release) |
| 112 | + STACKABLECTL_SKIP_RELEASE="true" |
| 113 | + ;; |
| 114 | + --skip-delete) |
| 115 | + KUTTL_SKIP_DELETE="true" |
| 116 | + ;; |
| 117 | + --parallel) |
| 118 | + KUTTL_PARALLEL="$2" |
| 119 | + shift |
| 120 | + ;; |
| 121 | + --test-suite) |
| 122 | + BEKU_TEST_SUITE="$2" |
| 123 | + shift |
| 124 | + ;; |
| 125 | + --test) |
| 126 | + KUTTL_TEST="$2" |
| 127 | + shift |
| 128 | + ;; |
| 129 | + *) |
| 130 | + echo "Unknown parameter : $1" |
| 131 | + usage |
| 132 | + exit 1 |
| 133 | + ;; |
| 134 | + esac |
| 135 | + shift |
| 136 | + done |
| 137 | +} |
| 138 | + |
| 139 | +main() { |
| 140 | + parse_args "$@" |
| 141 | + |
| 142 | + is_installed beku "https://github.com/stackabletech/beku.py" |
| 143 | + is_installed stackablectl "https://github.com/stackabletech/stackable-cockpit/blob/main/rust/stackablectl/README.md" |
| 144 | + is_installed kubectl "https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/" |
| 145 | + is_installed kubectl-kuttl "https://kuttl.dev/" |
| 146 | + |
| 147 | + expand_test_suite |
| 148 | + install_operators |
| 149 | + run_tests |
| 150 | +} |
| 151 | + |
| 152 | +main "$@" |
0 commit comments