Skip to content

Commit

Permalink
tests(api) replace tavern tests with bash
Browse files Browse the repository at this point in the history
  • Loading branch information
gszr committed Feb 1, 2021
1 parent 9597069 commit f1cbbd2
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ kong
docker-kong
id_rsa.private
kong_license.private
*.deb
*.rpm
25 changes: 22 additions & 3 deletions test/kong-tests-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
restart: on-failure
networks:
- kong-net

kong-migrations-up:
image: "${KONG_TEST_IMAGE_NAME:-kong:latest}"
Expand All @@ -29,6 +31,8 @@ services:
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
restart: on-failure
networks:
- kong-net

kong:
image: "${KONG_TEST_IMAGE_NAME:-kong:latest}"
Expand All @@ -40,23 +44,31 @@ services:
environment:
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_PROXY_LISTEN: "0.0.0.0:8000"
KONG_ADMIN_LISTEN: "0.0.0.0:8001"
KONG_PLUGINS: "${KONG_PLUGINS:-bundled}"
KONG_CASSANDRA_CONTACT_POINTS: db
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: 127.0.0.1
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
network_mode: "host"
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
restart: on-failure

networks:
- kong-net
ports:
- "8000:8000/tcp"
- "127.0.0.1:8001:8001/tcp"
- "8443:8443/tcp"
- "127.0.0.1:8444:8444/tcp"

db:
image: postgres:9.5
ports:
Expand All @@ -80,3 +92,10 @@ services:
interval: 5s
timeout: 10s
retries: 10
networks:
- kong-net

networks:
kong-net:
external: false

2 changes: 1 addition & 1 deletion test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
USE_TTY="-t"
test -t 1 && USE_TTY="-it"

for dir in test/tests/*; do
for dir in test/tests/02-*; do
msg_test "Running '$dir' tests..."
msg_test "======================================================================"

Expand Down
7 changes: 0 additions & 7 deletions test/tests/02-api/Dockerfile.test_runner

This file was deleted.

3 changes: 0 additions & 3 deletions test/tests/02-api/down.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

stop_kong

# update cache image
$UPDATE_CACHE_COMMAND kong/kong-build-tools:test-runner-$TEST_SHA

2 changes: 0 additions & 2 deletions test/tests/02-api/pytest.ini

This file was deleted.

27 changes: 0 additions & 27 deletions test/tests/02-api/requirements.txt

This file was deleted.

29 changes: 19 additions & 10 deletions test/tests/02-api/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
docker run \
--rm \
-t --network host \
-e RESTY_VERSION=$RESTY_VERSION \
-e KONG_VERSION=$KONG_VERSION \
-e ADMIN_URI=$KONG_ADMIN_URI \
-e PROXY_URI=$KONG_PROXY_URI \
-v $PWD:/app \
kong/kong-build-tools:test-runner-$TEST_SHA \
/bin/bash -c "py.test -p no:logging -p no:warnings test_*.tavern.yaml"
set pipefail

echo "Check admin API is alive"
assert_response "$KONG_ADMIN_URI" "200"

echo "Create a service"
assert_response "-d name=testservice -d url=http://httpbin.org $KONG_ADMIN_URI/services" "201"

echo "List services"
assert_response "$KONG_ADMIN_URI/services" "200"

echo "Create a route"
assert_response "-d name=testroute -d paths=/ $KONG_ADMIN_URI/services/testservice/routes" "201"

echo "List services"
assert_response "$KONG_ADMIN_URI/services" "200"

echo "Proxy a request"
assert_response "$KONG_PROXY_URI/anything" "200"
5 changes: 0 additions & 5 deletions test/tests/02-api/up.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@


start_kong
wait_kong

# build API tests docker image
$CACHE_COMMAND kong/kong-build-tools:test-runner-$TEST_SHA || \
docker build -t kong/kong-build-tools:test-runner-$TEST_SHA -f Dockerfile.test_runner .

4 changes: 4 additions & 0 deletions test/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ wait_kong() {
done
}

assert_response() {
RES=`curl -s -o /dev/null -w %{http_code} $1`
[ $RES == $2 ]
}

0 comments on commit f1cbbd2

Please sign in to comment.