Skip to content

Commit

Permalink
move tests to internal/ and update travis.yml file.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiam committed Feb 19, 2020
1 parent 086276d commit ba8fc2d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
28 changes: 13 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
sudo: false
dist: bionic

sudo: required

notifications:
email: false

language: go

go:
- 1.11.x
- 1.12.x
- 1.13.x
- "1.12"
- "1.13"

services:
- docker

env:
global:
- GOARCH=amd64
- TEST_HOST=127.0.0.1

addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10

before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
- "sudo service postgresql restart 10"
- sudo service mysql stop
- sudo service postgresql stop
- sleep 10

install:
- mkdir -p $GOPATH/src/upper.io
Expand All @@ -35,4 +32,5 @@ install:
- export TRAVIS_BUILD_DIR=$GOPATH/src/upper.io/bond

script:
- make test
- make -C internal/tests server-up test server-down

28 changes: 22 additions & 6 deletions Makefile → internal/tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
PROJECT ?= bond

DB_HOST ?= 127.0.0.1
DB_PORT ?= 5432
DB_USER ?= postgres
DB_PASSWORD ?=
DB_PASSWORD ?= postgr3s

BOND_DB ?= bond_test
BOND_USER ?= bond_user
BOND_PASSWORD ?= bond_password

TEST_FLAGS ?=

all: test
export POSTGRES_VERSION

build:
@go build
export DB_HOST
export DB_NAME
export DB_PASSWORD
export DB_PORT
export DB_USERNAME

test: resetdb
export TEST_FLAGS

all: test

test: db-reset
UPPERIO_DB_DEBUG=1 go test -v ./... $(TEST_FLAGS)

resetdb:
db-reset:
export PGPASSWORD="$(DB_PASSWORD)" && \
psql -U$(DB_USER) -h$(DB_HOST) -p$(DB_PORT) -c "DROP DATABASE IF EXISTS $(BOND_DB)" && \
psql -U$(DB_USER) -h$(DB_HOST) -p$(DB_PORT) -c "DROP ROLE IF EXISTS $(BOND_USER)" && \
Expand All @@ -26,3 +35,10 @@ resetdb:
psql -U$(DB_USER) -h$(DB_HOST) -p$(DB_PORT) -c "GRANT ALL PRIVILEGES ON DATABASE $(BOND_DB) TO $(BOND_USER)"
export PGPASSWORD="$(BOND_PASSWORD)" && \
psql -U$(BOND_USER) -h$(DB_HOST) -p$(DB_PORT) $(BOND_DB) < test_schema.sql

server-up: server-down
docker-compose -p $(PROJECT) up -d && \
sleep 10

server-down:
docker-compose -p $(PROJECT) down
File renamed without changes.
12 changes: 12 additions & 0 deletions internal/tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'

services:

server:
image: postgres:${POSTGRES_VERSION:-11}
environment:
POSTGRES_USER: ${DB_USERNAME:-postgres}
POSTGRES_PASSWORD: ${DB_PASSWORD:-postgr3s}
ports:
- '${DB_HOST:-127.0.0.1}:${DB_PORT:-5432}:5432'

File renamed without changes.
File renamed without changes.

0 comments on commit ba8fc2d

Please sign in to comment.