Skip to content

Commit

Permalink
make e2e tests more usable with docker-compose (#1770)
Browse files Browse the repository at this point in the history
* make docker-compose calls more flexible for older versions

Signed-off-by: Bob Callaway <[email protected]>

* start/stop pubsub

Signed-off-by: Bob Callaway <[email protected]>

---------

Signed-off-by: Bob Callaway <[email protected]>
  • Loading branch information
bobcallaway authored Oct 15, 2023
1 parent 2011c42 commit 05cca49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
25 changes: 17 additions & 8 deletions e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
set -e
testdir=$(dirname "$0")

docker_compose="docker compose -f docker-compose.yml -f docker-compose.test.yml"
if ! ${docker_compose} version 2&>1 >/dev/null; then
docker_compose="docker-compose -f docker-compose.yml -f docker-compose.test.yml"
fi

rm -f /tmp/pkg-rekor-*.cov
echo "installing gocovmerge"
make gocovmerge

echo "building test-only containers"
docker build -t gcp-pubsub-emulator -f Dockerfile.pubsub-emulator .
docker kill $(docker ps -q) || true

echo "starting services"
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
${docker_compose} up -d --build

echo "building CLI and server"
# set the path to the root of the repo
Expand All @@ -32,7 +41,7 @@ go test -c ./cmd/rekor-server -o rekor-server -covermode=count -coverpkg=./...

count=0
echo -n "waiting up to 120 sec for system to start"
until [ $(docker-compose ps | grep -c "(healthy)") == 3 ];
until [ $(${docker_compose} ps | grep -c "(healthy)") == 4 ];
do
if [ $count -eq 12 ]; then
echo "! timeout reached"
Expand All @@ -51,23 +60,23 @@ cp $dir/rekor-cli $REKORTMPDIR/rekor-cli
touch $REKORTMPDIR.rekor.yaml
trap "rm -rf $REKORTMPDIR" EXIT
if ! REKORTMPDIR=$REKORTMPDIR go test -tags=e2e $(go list ./... | grep -v ./tests) ; then
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
if ${docker_compose} logs --no-color | grep -q "panic: runtime error:" ; then
# if we're here, we found a panic
echo "Failing due to panics detected in logs"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi

echo "generating code coverage"
docker-compose restart rekor-server
${docker_compose} restart rekor-server

if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/pkg-rekor-server.cov ; then
if ! docker cp $(docker ps -aqf "name=rekor_rekor-server" -f "name=rekor-rekor-server"):go/rekor-server.cov /tmp/pkg-rekor-server.cov ; then
# failed to copy code coverage report from server
echo "Failed to retrieve server code coverage report"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi

Expand Down
31 changes: 15 additions & 16 deletions tests/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
set -e
testdir=$(dirname "$0")

docker_compose="docker compose -f docker-compose.yml -f docker-compose.test.yml"
if ! ${docker_compose} version 2&>1 >/dev/null; then
docker_compose="docker-compose -f docker-compose.yml -f docker-compose.test.yml"
fi

rm -f /tmp/rekor-*.cov

echo "installing gocovmerge"
Expand All @@ -26,7 +31,7 @@ echo "building test-only containers"
docker build -t gcp-pubsub-emulator -f Dockerfile.pubsub-emulator .

echo "starting services"
docker compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
${docker_compose} up -d --build

echo "building CLI and server"
go test -c ./cmd/rekor-cli -o rekor-cli -cover -covermode=count -coverpkg=./...
Expand All @@ -35,8 +40,8 @@ go test -c ./cmd/rekor-server -o rekor-server -covermode=count -coverpkg=./...
count=0

echo "waiting up to 2 min for system to start"
until [ $(docker compose ps | \
grep -E "(rekor-mysql|rekor-redis|rekor-server|gcp-pubsub-emulator)" | \
until [ $(${docker_compose} ps | \
grep -E "(rekor[-_]mysql|rekor[-_]redis|rekor[-_]rekor-server|rekor[-_]gcp-pubsub-emulator)" | \
grep -c "(healthy)" ) == 4 ];
do
if [ $count -eq 24 ]; then
Expand All @@ -55,33 +60,27 @@ REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)"
touch $REKORTMPDIR.rekor.yaml
trap "rm -rf $REKORTMPDIR" EXIT
if ! REKORTMPDIR=$REKORTMPDIR go test -tags=e2e ./tests/ -run TestIssue1308; then
docker compose logs --no-color > /tmp/docker compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
if ! REKORTMPDIR=$REKORTMPDIR PUBSUB_EMULATOR_HOST=localhost:8085 go test -tags=e2e ./tests/; then
docker compose logs --no-color > /tmp/docker compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
if docker compose logs --no-color | grep -q "panic: runtime error:" ; then
if ${docker_compose} logs --no-color | grep -q "panic: runtime error:" ; then
# if we're here, we found a panic
echo "Failing due to panics detected in logs"
docker compose logs --no-color > /tmp/docker compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi

echo "generating code coverage"
docker compose restart rekor-server

# docker compose appears to name the containers slightly differently in GHA CI vs locally on macOS
container_name="rekor_rekor-server"
if [[ "$(uname -s)" -eq "Darwin" ]]; then
container_name="rekor-rekor-server"
fi
${docker_compose} restart rekor-server

if ! docker cp $(docker ps -aqf "name=${container_name}"):/go/rekor-server.cov /tmp/rekor-server.cov ; then
if ! docker cp $(docker ps -aqf "name=rekor_rekor-server" -f "name=rekor-rekor-server"):/go/rekor-server.cov /tmp/rekor-server.cov ; then
# failed to copy code coverage report from server
echo "Failed to retrieve server code coverage report"
docker compose logs --no-color > /tmp/docker compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi

Expand Down

0 comments on commit 05cca49

Please sign in to comment.