-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from cdalvaro/refactor/tests
ref: Change tests architecture
- Loading branch information
Showing
7 changed files
with
153 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
.github/ | ||
.git/ | ||
|
||
# Ignoring tests files | ||
tests/ | ||
|
||
# Ignoring markdown files | ||
*.md | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,11 +74,13 @@ jobs: | |
platform: [linux/amd64, linux/arm64, linux/arm/v7] | ||
env: | ||
DOCKER_CLI_EXPERIMENTAL: enabled | ||
SALTAPI_URL: https://localhost:8000/ | ||
SALTAPI_USER: salt_api | ||
SALTAPI_PASS: 4wesome-Pass0rd | ||
SALTAPI_EAUTH: pam | ||
PLATFORM: ${{ matrix.platform }} | ||
BOOTUP_WAIT_SECONDS: 90 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
|
||
- name: Download Docker registry data from build job | ||
uses: actions/download-artifact@v2 | ||
with: | ||
|
@@ -106,69 +108,17 @@ jobs: | |
- name: Docker inspect | ||
run: docker buildx imagetools inspect ${IMAGE_NAME} | grep '${{ matrix.platform }}' | ||
|
||
- name: Launch docker container | ||
run: | | ||
# Create configuration files | ||
mkdir -p /tmp/config/ | ||
cat > /tmp/config/salt-api.conf <<EOF | ||
external_auth: | ||
${SALTAPI_EAUTH}: | ||
${SALTAPI_USER}: | ||
- .* | ||
- '@runner' | ||
- '@wheel' | ||
- '@jobs' | ||
EOF | ||
# Run test instance | ||
docker run --rm --detach --name saltstack_master \ | ||
--publish 4505:4505 --publish 4506:4506 --publish 8000:8000 \ | ||
--env 'SALT_API_SERVICE_ENABLED=true' \ | ||
--env 'SALT_API_USER_PASS=${{ env.SALTAPI_PASS }}' \ | ||
--platform ${{ matrix.platform }} \ | ||
--volume /tmp/config:/home/salt/data/config:ro \ | ||
${IMAGE_NAME} | ||
# Wait for salt-master bootup | ||
sleep 60 | ||
- name: Show salt versions | ||
run: docker exec saltstack_master salt --versions | ||
|
||
- name: Test image calling healthcheck | ||
run: docker exec saltstack_master /usr/local/sbin/healthcheck | ||
|
||
- name: Test salt-api authentication | ||
id: salt_api_auth | ||
run: | | ||
SALTAPI_TOKEN=$(curl -sSk https://localhost:8000/login \ | ||
-H 'Accept: application/x-yaml' \ | ||
-d username=${{ env.SALTAPI_USER }} \ | ||
-d password=${{ env.SALTAPI_PASS }} \ | ||
-d eauth=${{ env.SALTAPI_EAUTH }} | grep 'token:' | cut -d' ' -f 4) | ||
[ -n "${SALTAPI_TOKEN}" ] || exit 1 | ||
echo "::set-output name=token::${SALTAPI_TOKEN}" | ||
- name: Test salt-api command | ||
run: | | ||
curl -sSk https://localhost:8000 \ | ||
-H 'Accept: application/x-yaml' \ | ||
-H 'X-Auth-Token: ${{ steps.salt_api_auth.outputs.token }}' \ | ||
-d client=runner \ | ||
-d tgt='*' \ | ||
-d fun=test.stream | ||
- name: Setup Python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install salt-pepper | ||
run: pip install salt-pepper | ||
- name: Execute basic tests | ||
run: tests/basic/test.sh | ||
|
||
- name: Test salt-pepper | ||
run: pepper --client runner test.stream | ||
- name: Execute salt-api tests | ||
run: tests/salt-api/test.sh | ||
|
||
- name: Cleanup | ||
run: | | ||
docker stop saltstack_master registry | ||
docker stop registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Basic Tests | ||
|
||
Checks: | ||
|
||
- the image has the right `salt-master` version installed. | ||
- the `healthcheck` is working. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
[ "${DEBUG}" == true ] && set -vx | ||
|
||
echo "🧪 Running basic tests ..." | ||
|
||
IMAGE_NAME=${IMAGE_NAME:-cdalvaro/docker-salt-master} | ||
CONTAINER_NAME=salt_master | ||
PLATFORM=${PLATFORM:-$(docker version --format='{{.Server.Os}}/{{.Server.Arch}}')} | ||
BOOTUP_WAIT_SECONDS=${BOOTUP_WAIT_SECONDS:-60} | ||
|
||
function cleanup { | ||
echo "==> Removing ${CONTAINER_NAME} ..." | ||
docker container rm --force "${CONTAINER_NAME}" | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
# Run test instance | ||
echo "==> Starting docker-salt-master (${PLATFORM}) ..." | ||
docker run --rm --detach --name "${CONTAINER_NAME}" \ | ||
--publish 4505:4505 --publish 4506:4506 \ | ||
--platform "${PLATFORM}" \ | ||
"${IMAGE_NAME}" || ( echo "container started ❌"; exit 1 ) | ||
echo "container started ✅" | ||
|
||
# Wait for salt-master bootup | ||
echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..." | ||
sleep "${BOOTUP_WAIT_SECONDS}" | ||
|
||
# Check salt version | ||
echo "==> Checking salt version ..." | ||
docker exec "${CONTAINER_NAME}" salt --versions | ||
[[ "$(docker exec ${CONTAINER_NAME} salt --version)" == "salt $(cat VERSION)" ]] || ( echo "salt version ❌"; exit 1 ) | ||
echo "salt version ✅" | ||
|
||
# Test image calling healthcheck | ||
echo "==> Executing healthcheck ..." | ||
docker exec "${CONTAINER_NAME}" /usr/local/sbin/healthcheck | grep -i 'true' || ( echo "healthcheck ❌"; exit 1 ) | ||
echo "healthcheck ✅" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Salt API Tests | ||
|
||
Checks: | ||
|
||
- `salt-api` provides a token via `curl`. | ||
- executes `salt-api` command via `curl`. | ||
- installs and tries `salt-pepper`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
[ "${DEBUG}" == true ] && set -vx | ||
|
||
echo "🧪 Running salt-api tests ..." | ||
|
||
IMAGE_NAME=${IMAGE_NAME:-cdalvaro/docker-salt-master} | ||
CONTAINER_NAME=salt_master | ||
PLATFORM=${PLATFORM:-$(docker version --format='{{.Server.Os}}/{{.Server.Arch}}')} | ||
BOOTUP_WAIT_SECONDS=${BOOTUP_WAIT_SECONDS:-60} | ||
|
||
export SALTAPI_URL="https://localhost:8000/" | ||
export SALTAPI_USER=salt_api | ||
export SALTAPI_PASS=4wesome-Pass0rd | ||
export SALTAPI_EAUTH=pam | ||
export SALTAPI_TMP_DIR=${SALTAPI_TMP_DIR:-/tmp/salt-api} | ||
|
||
function cleanup { | ||
echo "==> Removing ${CONTAINER_NAME} ..." | ||
docker container rm --force "${CONTAINER_NAME}" | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
# Create configuration files | ||
echo "==> Creating salt-api configuration file ..." | ||
mkdir -p "${SALTAPI_TMP_DIR}/config/" | ||
cat > "${SALTAPI_TMP_DIR}/config/salt-api.conf" <<EOF | ||
external_auth: | ||
${SALTAPI_EAUTH}: | ||
${SALTAPI_USER}: | ||
- .* | ||
- '@runner' | ||
- '@wheel' | ||
- '@jobs' | ||
EOF | ||
echo "salt-api config created ✅" | ||
|
||
# Run test instance | ||
echo "==> Starting docker-salt-master (${PLATFORM}) with salt-api config ..." | ||
docker run --rm --detach --name "${CONTAINER_NAME}" \ | ||
--publish 4505:4505 --publish 4506:4506 --publish 8000:8000 \ | ||
--env SALT_API_SERVICE_ENABLED=true \ | ||
--env SALT_API_USER_PASS="${SALTAPI_PASS}" \ | ||
--platform "${PLATFORM}" \ | ||
--volume "${SALTAPI_TMP_DIR}/config":/home/salt/data/config:ro \ | ||
"${IMAGE_NAME}" || ( echo "container started ❌"; exit 1 ) | ||
echo "container started ✅" | ||
|
||
# Wait for salt-master bootup | ||
echo "==> Waiting ${BOOTUP_WAIT_SECONDS} seconds for the container to be ready ..." | ||
sleep "${BOOTUP_WAIT_SECONDS}" | ||
|
||
# Test salt-api authentication | ||
echo "==> Getting salt-api token ..." | ||
SALTAPI_TOKEN=$(curl -sSk "${SALTAPI_URL%/}/login" \ | ||
-H "Accept: application/x-yaml" \ | ||
-d username="${SALTAPI_USER}" \ | ||
-d password="${SALTAPI_PASS}" \ | ||
-d eauth="${SALTAPI_EAUTH}" | grep 'token:' | cut -d' ' -f 4) | ||
[ -n "${SALTAPI_TOKEN}" ] || ( echo "salt-api token ❌"; exit 1 ) | ||
echo "salt-api token ✅" | ||
|
||
# Test salt-api command | ||
echo "==> Testing curl command ..." | ||
curl -sSk "${SALTAPI_URL}" \ | ||
-H "Accept: application/x-yaml" \ | ||
-H "X-Auth-Token: ${SALTAPI_TOKEN}" \ | ||
-d client=runner \ | ||
-d tgt='*' \ | ||
-d fun=test.stream \ | ||
| grep -i 'true' || ( echo "curl command ❌"; exit 1 ) | ||
echo "curl command ✅" | ||
|
||
# Install salt-pepper | ||
echo "==> Installing salt-pepper ..." | ||
pip3 install salt-pepper || ( echo "pepper installed ❌"; exit 1 ) | ||
echo "pepper installed ✅" | ||
|
||
# Test salt-pepper | ||
echo "==> Testing salt-pepper ..." | ||
pepper -vvv --debug-http --ignore-ssl-errors --client runner test.stream|| ( echo "pepper test.stream ❌"; exit 1 ) | ||
echo "pepper test.stream ✅" |