From 5c3a4c995856892e8169451ddd391bb600b2cb51 Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Fri, 13 Sep 2024 14:21:17 -0400 Subject: [PATCH] Reintroduce test suite for install script The original location of the Teleport installation script included a test suite based on Docker Compose. Add the test suite to the new location along with the original GitHub Actions workflow that ran on changes to the installation script. --- .github/workflows/test-installation.yaml | 16 +++ .../install-teleport-tests/README.md | 66 ++++++++++++ .../install-teleport-tests/docker-compose.yml | 102 ++++++++++++++++++ .../install-teleport-tests/run-all-tests.sh | 8 ++ .../install-teleport-tests/run-test.sh | 60 +++++++++++ 5 files changed, 252 insertions(+) create mode 100644 .github/workflows/test-installation.yaml create mode 100644 assets/install-scripts/install-teleport-tests/README.md create mode 100644 assets/install-scripts/install-teleport-tests/docker-compose.yml create mode 100644 assets/install-scripts/install-teleport-tests/run-all-tests.sh create mode 100644 assets/install-scripts/install-teleport-tests/run-test.sh diff --git a/.github/workflows/test-installation.yaml b/.github/workflows/test-installation.yaml new file mode 100644 index 0000000000000..d7c7ff2f26b35 --- /dev/null +++ b/.github/workflows/test-installation.yaml @@ -0,0 +1,16 @@ +name: Test installation script + +on: + pull_request: + paths: + - "assets/install-scripts/install.sh" + +jobs: + check: + if: ${{ !github.event.pull_request.draft }} + name: Run tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: bash run-all-tests.sh + working-directory: ./assets/install-scripts/install-teleport-tests diff --git a/assets/install-scripts/install-teleport-tests/README.md b/assets/install-scripts/install-teleport-tests/README.md new file mode 100644 index 0000000000000..3a0f54b79d5a5 --- /dev/null +++ b/assets/install-scripts/install-teleport-tests/README.md @@ -0,0 +1,66 @@ +# Installation script test environment + +`assets/install-scripts/install-teleport-tests` contains the test environment +for the one-line Teleport installation script available at +`https://goteleport.com/static/install.sh`. + +## How the test suite works + +The test suite uses `docker compose` to launch containers based on a number of +Linux distributions. Each container mounts the installation script and runs it, +then runs a command to make assertions against the results of the installation +script. + +If an assertion fails, the container running the script prints a log that +includes the string `INSTALL_SCRIPT_TEST_FAILURE`. After running containers, the +test suite looks up instances of the failure log and, if it finds any, exits +with an error code. + +## Run the test suite + +```bash +$ cd assets/install-scripts/install-teleport-tests +$ bash run-all-tests.sh +``` + +## Run a single test case + +Run the `docker compose` service that corresponds to the test case you want to +run: + +```bash +$ cd assets/install-scripts/install-teleport-tests +$ docker compose up +``` + +Consult `docker-compose.yml` for the available test cases. + +## Add a test + +1. Add a service definition to `docker-compose.yml`. +1. Add the following bind mounts to the service definition: + + ```yaml + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + ``` + +1. Edit the `command` field of the service definition to include the following: + + ```yaml + bash /install.sh 15.0.0; + bash /run-test.sh oss' + ``` + + Edit the parameters of the `install.sh` and `run-tests.sh` scripts as + appropriate. The edition parameter of the two must match (the default edition + parameter for `install.sh` is `oss`). + +1. To add an assertion to the test suite, edit `run-test.sh`. Each assertion + must print a log that includes the string `INSTALL_SCRIPT_TEST_FAILURE` if it + fails. diff --git a/assets/install-scripts/install-teleport-tests/docker-compose.yml b/assets/install-scripts/install-teleport-tests/docker-compose.yml new file mode 100644 index 0000000000000..a3231cdb23408 --- /dev/null +++ b/assets/install-scripts/install-teleport-tests/docker-compose.yml @@ -0,0 +1,102 @@ +version: "3.8" +services: + test-ubuntu-jammy-cloud: + image: ubuntu:22.04 + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + # Need to install curl on the ubuntu container + command: | + bash -c 'apt-get update; + apt-get install -y curl; + bash /install.sh 15.1.0 cloud; + bash /run-test.sh cloud' + + test-ubuntu-jammy-no-edition: + image: ubuntu:22.04 + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + # Need to install curl on the ubuntu container + command: | + bash -c 'apt-get update; + apt-get install -y curl; + bash /install.sh 15.0.0; + bash /run-test.sh oss' + + test-debian-bookworm-oss: + image: debian:bookworm + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + # Need to install curl on the debian container + command: | + bash -c 'apt-get update; + apt-get install -y curl; + bash /install.sh 15.0.0 oss; + bash /run-test.sh oss' + + test-rocky-9-enterprise: + image: rockylinux:9 + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + command: | + bash -c 'bash /install.sh 15.0.0 enterprise; + bash /run-test.sh enterprise' + + test-sles-cloud: + image: registry.suse.com/bci/bci-base:15.5 + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + # We need to install awk on the SLES container to run + # the installation script. + command: | + bash -c ' + zypper update -y; + zypper install -y awk; + bash /install.sh 15.1.0 cloud; + bash /run-test.sh cloud' + + # Ensure that the installation script completes as expected when the ID_LIKE + # value in /etc/os-release is "ubuntu debian", as it is on Linux Mint and + # Pop!_OS. + test-ubuntu-debian: + image: ubuntu:22.04 + volumes: + - type: bind + source: ../install.sh + target: /install.sh + - type: bind + source: ./run-test.sh + target: /run-test.sh + # Need to install curl on the ubuntu container + command: | + bash -c 'apt-get update; + apt-get install -y curl; + sed -E -i "s/ID_LIKE=.*$/ID_LIKE=\"ubuntu debian\"/" /etc/os-release; + bash /install.sh 15.0.0; + bash /run-test.sh oss' + + diff --git a/assets/install-scripts/install-teleport-tests/run-all-tests.sh b/assets/install-scripts/install-teleport-tests/run-all-tests.sh new file mode 100644 index 0000000000000..9c6dc15d704ae --- /dev/null +++ b/assets/install-scripts/install-teleport-tests/run-all-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e -o pipefail +docker compose up +if docker compose logs | grep "INSTALL_SCRIPT_TEST_FAILURE"; then + echo "ONE OR MORE TESTS FAILED" + exit 1 +fi +echo "ALL TESTS COMPLETED SUCCESSFULLY" diff --git a/assets/install-scripts/install-teleport-tests/run-test.sh b/assets/install-scripts/install-teleport-tests/run-test.sh new file mode 100644 index 0000000000000..087a487555f05 --- /dev/null +++ b/assets/install-scripts/install-teleport-tests/run-test.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# $1: edition: cloud, oss, or enterprise +function test_teleport() { + if ! type teleport; then + echo "INSTALL_SCRIPT_TEST_FAILURE: teleport not found" + fi +} + +function test_tctl() { + if ! type tctl; then + echo "INSTALL_SCRIPT_TEST_FAILURE: tctl not found" + fi +} + +function test_tsh() { + if ! type tsh; then + echo "INSTALL_SCRIPT_TEST_FAILURE: tsh not found" + fi +} + +function test_tbot() { + if ! type tctl; then + echo "INSTALL_SCRIPT_TEST_FAILURE: tbot not found" + fi +} + +function test_upgrader() { + if ! type teleport-upgrade; then + echo "INSTALL_SCRIPT_TEST_FAILURE: upgrader not found" + fi +} + +echo "RUNNING TEST" + +case $1 in + cloud) + test_teleport + test_tctl + test_tsh + test_tbot + test_upgrader + ;; + oss) + test_teleport + test_tctl + test_tsh + test_tbot + ;; + enterprise) + test_teleport + test_tctl + test_tsh + test_tbot + ;; + *) + echo "INSTALL_SCRIPT_TEST_FAILURE: unsupported edition $EDITION" + ;; +esac + +