Skip to content

Commit

Permalink
cleanup testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Sep 16, 2022
1 parent 42e5c2f commit 9a05798
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 103 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/tests.yml
@@ -1,7 +1,8 @@
name: Tests
on:
push:
branches: [ main ]
branches:
- main
pull_request:

jobs:
Expand All @@ -22,7 +23,7 @@ jobs:
ports:
- 3307:3306
# needed because the mysql container does not provide a healthcheck
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 10s --health-timeout 5s --health-retries 5
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 5s --health-timeout 5s --health-retries 10

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -59,15 +60,15 @@ jobs:

services:
postgres:
image: postgres:14
image: postgres:10
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
- 5433:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -113,8 +114,10 @@ jobs:
run: |
mkdir -p crdb/certs
pushd crdb
wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.4.linux-amd64.tgz | tar zxv
mv cockroach-v20.2.4.linux-amd64/cockroach .
wget -qO- https://binaries.cockroachdb.com/cockroach-v21.1.19.linux-amd64.tgz | tar -xz
mv cockroach-v21.1.19.linux-amd64/* .
ln -s `pwd`/cockroach /usr/local/bin/
cockroach version
./cockroach cert create-ca --certs-dir certs --ca-key key
./cockroach cert create-client root --certs-dir certs --ca-key key
./cockroach cert create-node localhost 127.0.0.1 `hostname -s` `hostname -f` --certs-dir certs --ca-key key
Expand Down Expand Up @@ -156,14 +159,16 @@ jobs:
run: |
mkdir -p crdb
pushd crdb
wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.4.linux-amd64.tgz | tar zxv
mv cockroach-v20.2.4.linux-amd64/cockroach .
wget -qO- https://binaries.cockroachdb.com/cockroach-v21.1.19.linux-amd64.tgz | tar -xz
mv cockroach-v21.1.19.linux-amd64/* .
ln -s `pwd`/cockroach /usr/local/bin/
./cockroach start-single-node --insecure --background
popd
- name: Build and run soda
env:
SODA_DIALECT: "cockroach"
COCKROACH_PORT: 26257
run: |
go build -v -tags sqlite -o tsoda ./soda
./tsoda drop -e $SODA_DIALECT -p ./testdata/migrations
Expand All @@ -173,6 +178,7 @@ jobs:
- name: Test
env:
SODA_DIALECT: "cockroach"
COCKROACH_PORT: 26257
run: |
go test -tags sqlite -race -cover ./...
Expand Down
21 changes: 0 additions & 21 deletions Makefile
Expand Up @@ -7,36 +7,15 @@ GO_BIN ?= go
install: deps
$(GO_BIN) install -tags ${TAGS} -v ./soda

deps:
$(GO_BIN) get github.com/gobuffalo/release
$(GO_BIN) get -tags ${TAGS} -t ./...
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
endif

build:
$(GO_BIN) build -v .

test:
$(GO_BIN) test -tags ${TAGS} ./...

ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...

lint:
golangci-lint run

update:
$(GO_BIN) get -u -tags ${TAGS}
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
endif
make test
make install
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
endif

release-test:
./test.sh

Expand Down
4 changes: 2 additions & 2 deletions database.yml
Expand Up @@ -9,7 +9,7 @@ mysql:
readTimeout: 5s

postgres:
url: {{ envOr "POSTGRESQL_URL" "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable" }}
url: {{ envOr "POSTGRESQL_URL" "postgres://postgres:postgres@localhost:5433/pop_test?sslmode=disable" }}
pool: 25

cockroach:
Expand All @@ -29,5 +29,5 @@ cockroach_ssl:

sqlite:
dialect: "sqlite3"
database: "./sql_scripts/sqlite/test.sqlite"
database: "tmp/test.sqlite"

40 changes: 28 additions & 12 deletions docker-compose.yml
Expand Up @@ -8,26 +8,42 @@ services:
- MYSQL_DATABASE=pop_test
- MYSQL_USER=pop
- MYSQL_PASSWORD=pop
volumes:
- ./sql:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
- "3307:3306"
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 5s
timeout: 5s
retries: 10
start_period: 3s

postgres:
image: postgres:10.21
image: postgres:10
environment:
- POSTGRES_DB=pop_test
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
ports:
- "5432:5432"
volumes:
- ./sqldumps:/docker-entrypoint-initdb.d
- "5433:5432"
healthcheck:
test: ["CMD", "pg_isready"]
interval: 5s
timeout: 5s
retries: 10
start_period: 3s

cockroach:
image: cockroachdb/cockroach:v20.2.4
user: ${CURRENT_UID:?"Please run as follows 'CURRENT_UID=$$(id -u):$$(id -g) docker-compose up'"}
image: cockroachdb/cockroach:latest-v21.1
ports:
- "26257:26257"
volumes:
- "./cockroach-data/roach1:/cockroach/cockroach-data"
- "26258:26257"
- "8081:8080"
#volumes:
#- ./_vol/cockroach:/cockroach/cockroach-data
command: start-single-node --insecure
healthcheck:
test: ["CMD", "curl", "http://localhost:8080/health"]
interval: 5s
timeout: 5s
retries: 10
start_period: 3s
95 changes: 36 additions & 59 deletions test.sh
@@ -1,84 +1,61 @@
#!/bin/bash

########################################################
# test.sh is a wrapper to execute integration tests for
# pop.
########################################################

set -e
clear

VERBOSE=""
DEBUG='NO'
# NOTE: See also docker-compose.yml and database.yml to configure database
# properties.
export MYSQL_PORT=3307
export COCKROACH_PORT=26258

for i in "$@"
do
case $i in
-v)
VERBOSE="-v"
shift
;;
-d)
DEBUG='YES'
shift
;;
*)
# unknown option
;;
esac
done
COMPOSE=docker-compose
which docker-compose || COMPOSE="docker compose"

args=$@

function cleanup {
echo "Cleanup resources..."
docker-compose down
$COMPOSE down
docker volume prune -f
rm tsoda
find ./sql_scripts/sqlite -name *.sqlite* -delete
find ./tmp -name *.sqlite* -delete || true
}
# defer cleanup, so it will be executed even after premature exit
trap cleanup EXIT

# The cockroach volume is created by the root user if no user is set.
# Therefore we set the current user according to https://github.com/docker/compose/issues/1532#issuecomment-619548112
CURRENT_UID="$(id -u):$(id -g)"
export CURRENT_UID

docker-compose up -d
sleep 5 # Ensure mysql is online

go build -v -tags sqlite -o tsoda ./soda

export GO111MODULE=on

function test {
echo "!!! Testing $1"
export SODA_DIALECT=$1
echo ./tsoda -v
echo "Setup..."

echo ""
echo "######################################################################"
echo "### Running unit tests for $SODA_DIALECT"
./tsoda drop -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda create -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda migrate -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
echo "Test..."
go test -race -tags sqlite $VERBOSE -count=1 ./...
go test -cover -race -tags sqlite -count=1 $args ./...
}

function debug_test {
echo "!!! Debug Testing $1"
export SODA_DIALECT=$1
echo ./tsoda -v
echo "Setup..."
./tsoda drop -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda create -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda migrate -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
echo "Test and debug..."
dlv test github.com/gobuffalo/pop
export SODA_DIALECT=$1

echo ""
echo "######################################################################"
echo "### Running unit tests for $SODA_DIALECT"
./tsoda drop -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda create -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
./tsoda migrate -e $SODA_DIALECT -c ./database.yml -p ./testdata/migrations
dlv test github.com/gobuffalo/pop
}

dialects=("postgres" "cockroach" "mysql" "sqlite")
dialects="postgres cockroach mysql sqlite"

$COMPOSE up --wait

go build -v -tags sqlite -o tsoda ./soda

for dialect in "${dialects[@]}" ; do
if [ $DEBUG = 'NO' ]; then
test ${dialect}
else
debug_test ${dialect}
fi
for dialect in $dialects; do
if [ "$DEBUG" = "YES" ]; then
debug_test ${dialect}
else
test ${dialect}
fi
done

0 comments on commit 9a05798

Please sign in to comment.