Skip to content

Commit

Permalink
Merge pull request #6 from danvergara/add-test-scripts
Browse files Browse the repository at this point in the history
Add test scripts
  • Loading branch information
danvergara committed Apr 5, 2021
2 parents 0253fde + 345fc80 commit 6197d52
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: test
## test: Runs the tests
test:
go test -v -race ./...

.PHONY: test-all
## test-all: Runs the integration testing bash script with different database docker image versions
test-all:
@./scripts/test_all.sh

.PHONY: help
## help: Prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
45 changes: 45 additions & 0 deletions scripts/test_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
#
# Integartion testing with dockerized database servers
#

set -e

# database credentials
export DBHOST=${DBHOST:-localhost}
export PGUSER="postgres"
export DBPASSWORD="password"
export DATABASE="users"
export PGPORT="15432"
export MYSQL_PORT="13306"

# Test different versions of postgres available on Docker Hub.
pgversions="9.6 10.16 11.11 12.6 13.2"

for i in $pgversions
do
PGVERSION="$i"
echo "--------------BEGIN POSTGRES TESTS-------------"
echo "Running test against PostgreSQL v$PGVERSION"
docker rm -f postgres || true
docker run -p $PGPORT:5432 --name postgres -e POSTGRES_PASSWORD=$DBPASSWORD -d postgres:$PGVERSION
sleep 5
make test
echo "--------------END POSTGRES TESTS-------------"
done


# Test different versions of mysql available on Docker Hub.
mysql_versions="5.6 5.7 8.0"

for i in $mysql_versions
do
MYSQL_VERSION="$i"
echo "--------------BEGIN MYSQL TESTS-------------"
echo "Running test against MySQL v$MYSQL_VERSION"
docker rm -f mysql || true
docker run -p $MYSQL_PORT:3306 --name mysql -e MYSQL_PASSWORD=$DBPASSWORD -d mysql:$MYSQL_VERSION
sleep 5
make test
echo "--------------END MYSQL TESTS-------------"
done

0 comments on commit 6197d52

Please sign in to comment.