Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Sep 12, 2024
1 parent e85eb1e commit 8910717
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ build_v2:

test: KONG_DOCKER_TAG?=$(DOCKER_TAG)
test:
if cd kong-build-tools; \
then git pull; \
else git clone https://github.com/Kong/kong-build-tools.git; fi
cd kong-build-tools && git reset --hard $(KONG_BUILD_TOOLS)
BASE=$(BASE) ./tests/test.sh --suite "Docker-Kong test suite"

release-rhel: build_v2
Expand Down
117 changes: 117 additions & 0 deletions tests/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash

msg_test() {
builtin echo -en "\033[1;34m" >&1
echo -n "===> "
builtin echo -en "\033[1;36m" >&1
echo -e "$@"
builtin echo -en "\033[0m" >&1
}

msg_yellow() {
builtin echo -en "\033[1;33m" >&1
echo -e "$@"
builtin echo -en "\033[0m" >&1
}

msg_green() {
builtin echo -en "\033[1;32m" >&1
echo -e "$@"
builtin echo -en "\033[0m" >&1
}

msg_red() {
builtin echo -en "\033[1;31m" >&2
echo -e "$@"
builtin echo -en "\033[0m" >&2
}

err_exit() {
msg_red "$@"
exit 1
}

wait_for() {
local i=$1
local char=${2:-.}
while [ "$i" -gt 0 ]; do
echo -n "$char"
i=$(( i-1 ))
sleep 1
done
echo
}

start_kong() {
KONG_FIPS=off
if [ "$SSL_PROVIDER" = "boringssl" ]; then
KONG_FIPS=on
fi
KONG_FIPS=$KONG_FIPS KONG_TEST_IMAGE_NAME=${1:-$KONG_TEST_IMAGE_NAME} docker-compose -f "$TEST_COMPOSE_PATH" up -d
}

stop_kong() {
KONG_TEST_IMAGE_NAME=${1:-$KONG_TEST_IMAGE_NAME} docker-compose -f "$TEST_COMPOSE_PATH" down
KONG_TEST_IMAGE_NAME=${1:-$KONG_TEST_IMAGE_NAME} docker-compose -f "$TEST_COMPOSE_PATH" rm -f
docker stop $(docker ps -a -q) || true
docker rm $(docker ps -a -q) || true
docker volume prune -f
}

kong_ready() {
local TIMEOUT_SECONDS=$((5 * 60))
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8000)" != 404 ]]; do
sleep 5;
COUNTER=$((COUNTER + 5))

if (($COUNTER >= $TIMEOUT_SECONDS))
then
printf "\xe2\x98\x93 ERROR: Timed out waiting for $KONG"
exit 1
fi
done
}

wait_kong() {
while ! kong_ready; do
msg_test "Waiting for Kong to be ready "
docker-compose -f "$TEST_COMPOSE_PATH" ps
docker-compose -f "$TEST_COMPOSE_PATH" logs kong
sleep 5
done
}

assert_response() {
local endpoint=$1
local expected_code=$2
local resp_code
COUNTER=20
while : ; do
resp_code=$(curl -s -o /dev/null -w "%{http_code}" $endpoint)
[ "$resp_code" == "$expected_code" ] && break
((COUNTER-=1))
[ "$COUNTER" -lt 1 ] && break
sleep 0.5 # 10 seconds max
done
[ "$resp_code" == "$expected_code" ] || err_exit " expected $2, got $resp_code"
}

it_runs_free_enterprise() {
info=$(curl $KONG_ADMIN_URI)
msg_test "it does not have ee-only plugins"
[ "$(echo $info | jq -r .plugins.available_on_server.canary)" != "true" ]
msg_test "it does not enable vitals"
[ "$(echo $info | jq -r .configuration.vitals)" == "false" ]
msg_test "workspaces are not writable"
assert_response "$KONG_ADMIN_URI/workspaces -d name=testworkspace" "403"
}

it_runs_full_enterprise() {
info=$(curl $KONG_ADMIN_URI)
msg_test "it does have ee-only plugins"
[ "$(echo $info | jq -r .plugins.available_on_server | jq -r 'has("canary")')" == "true" ]
msg_test "it does enable vitals"
[ "$(echo $info | jq -r .configuration.vitals)" == "true" ]
msg_test "workspaces are writable"
assert_response "$KONG_ADMIN_URI/workspaces -d name=testworkspace" "201"
}

0 comments on commit 8910717

Please sign in to comment.