ref(tests): Use common.sh on tests

This commit is contained in:
Carlos Álvaro
2021-11-04 19:48:55 +01:00
parent 73c617bb3d
commit c85cbbf000
4 changed files with 74 additions and 59 deletions

View File

@@ -5,10 +5,13 @@ set -e
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}
# https://stackoverflow.com/a/4774063/3398062
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# shellcheck source=assets/build/functions.sh
COMMON_FILE="${SCRIPT_PATH}/../lib/common.sh"
source "${COMMON_FILE}"
trap cleanup EXIT
export SALTAPI_URL="https://localhost:8000/"
export SALTAPI_USER=salt_api
@@ -16,13 +19,6 @@ 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/"
@@ -39,18 +35,13 @@ 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 \
start_container_and_wait \
--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}"
|| error "container started"
ok "container started"
# Test salt-api authentication
echo "==> Getting salt-api token ..."
@@ -59,8 +50,8 @@ SALTAPI_TOKEN=$(curl -sSk "${SALTAPI_URL%/}/login" \
-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"
[ -n "${SALTAPI_TOKEN}" ] || error "salt-api token"
ok "salt-api token"
# Test salt-api command
echo "==> Testing curl command ..."
@@ -70,15 +61,15 @@ curl -sSk "${SALTAPI_URL}" \
-d client=runner \
-d tgt='*' \
-d fun=test.stream \
| grep -i 'true' || ( echo "curl command ❌"; exit 1 )
echo "curl command"
| grep -i 'true' || error "curl command"
ok "curl command"
# Install salt-pepper
echo "==> Installing salt-pepper ..."
pip3 install salt-pepper || ( echo "pepper installed ❌"; exit 1 )
echo "pepper installed"
pip3 install salt-pepper || error "pepper installed"
ok "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"
pepper --client runner test.stream || error "pepper test.stream"
ok "pepper test.stream"