Skip to content

Instantly share code, notes, and snippets.

@dduportal
Last active August 12, 2020 09:42
Show Gist options
  • Save dduportal/0446e9d4851d6a3d526e2c14ec681317 to your computer and use it in GitHub Desktop.
Save dduportal/0446e9d4851d6a3d526e2c14ec681317 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bats
load "${BATS_HELPERS_DIR}/load.bash"
JENKINS_CONTAINER="${PROJECT_ID}_jenkins_1"
@test "Reverse Proxy service is up and healthy after a few seconds" {
retry_equals 10 2 '"healthy"' docker inspect -f '{{json .State.Health.Status}}' "${PROJECT_ID}_reverse-proxy_1"
}
@test "Jenkins service is up and healthy after some more seconds" {
retry_equals 120 1 '"healthy"' docker inspect -f '{{json .State.Health.Status}}' "${JENKINS_CONTAINER}"
}
#!/bin/bash
set -eu -o pipefail
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
TMP_DIR=${TMP_DIR:-/tmp}
## Cleanup
rm -rf "${CURRENT_DIR}/bats" "${TMP_DIR}/bats-core"
## Prepare
mkdir -p "${CURRENT_DIR}/helpers"
cat >"${CURRENT_DIR}/helpers/load.bash" <<EOF
#!/bin/bats
load "\${BATS_HELPERS_DIR}/bats-support/load.bash"
load "\${BATS_HELPERS_DIR}/bats-assert/load.bash"
load "\${BATS_HELPERS_DIR}/bats-file/load.bash"
load "\${BATS_HELPERS_DIR}/helpers.bash"
EOF
## Install bats from https://github.com/bats-core/bats-core
git clone https://github.com/bats-core/bats-core.git "${TMP_DIR}/bats-core"
bash "${TMP_DIR}/bats-core/install.sh" "${CURRENT_DIR}/bats"
## Install bats helper libraries from https://github.com/ztombol/bats-docs
for BATS_HELPER in bats-support bats-assert bats-file
do
git clone "https://github.com/ztombol/${BATS_HELPER}" "${CURRENT_DIR}/helpers/${BATS_HELPER}"
rm -rf "${CURRENT_DIR}/helpers/${BATS_HELPER}/.git" # No git tracking
done
BATS_HELPERS_DIR ?= $(CURDIR)/helpers
export BATS_HELPERS_DIR
BATS_BIN ?= $(CURDIR)/bats/bin/bats
tests:
$(BATS_BIN) $(CURDIR)/example.bats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment