Skip to content

Commit

Permalink
Reintroduce test suite for install script
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptgott committed Oct 10, 2024
1 parent 92faa33 commit 5c3a4c9
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test-installation.yaml
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions assets/install-scripts/install-teleport-tests/README.md
Original file line number Diff line number Diff line change
@@ -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 <TEST_CASE>
```

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.
102 changes: 102 additions & 0 deletions assets/install-scripts/install-teleport-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions assets/install-scripts/install-teleport-tests/run-test.sh
Original file line number Diff line number Diff line change
@@ -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


0 comments on commit 5c3a4c9

Please sign in to comment.