Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 4 additions & 8 deletions bond_test.go → internal/tests/bond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,13 @@ func dbConnected() bool {
return false
}
err := DB.Ping()
if err != nil {
return false
}
return true
return err == nil
}

func dbReset() {
cols, _ := DB.Collections()
for _, k := range cols {
DB.Collection(k).Truncate()
_ = DB.Collection(k).Truncate()
}
}

Expand Down Expand Up @@ -170,8 +167,7 @@ func TestAccount(t *testing.T) {
// -------
// Read
// -------
var acctChk *Account
acctChk = &Account{}
acctChk := &Account{}

err = DB.Account.Find(db.Cond{"id": acct.ID}).One(&acctChk)
assert.NoError(t, err)
Expand Down Expand Up @@ -237,7 +233,7 @@ func TestDelete(t *testing.T) {
assert.NoError(t, err)

err = DB.Account.Delete(&Account{Name: "X"})
assert.Error(t, bond.ErrZeroItemID)
assert.NoError(t, err)
}

func TestSlices(t *testing.T) {
Expand Down
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'

2 changes: 1 addition & 1 deletion model_test.go → internal/tests/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func dbUp() bond.Session {

cols, _ := sess.Collections()
for _, c := range cols {
sess.Collection(c).Truncate()
_ = sess.Collection(c).Truncate()
}

return sess
Expand Down
File renamed without changes.