Skip to content

Commit

Permalink
Merge pull request #473 from upper/hotfix/refactor-travis-script
Browse files Browse the repository at this point in the history
Refactor travis script
  • Loading branch information
xiam authored Dec 25, 2018
2 parents 1edc03a + 4ab5cec commit 2f58dea
Show file tree
Hide file tree
Showing 31 changed files with 528 additions and 427 deletions.
58 changes: 24 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,48 @@
dist: xenial

sudo: required

language: go

env:
global:
- GOARCH=amd64
- DB_HOST=127.0.0.1
matrix:
- TEST_CMD="make databases test" POSTGRESQL_VERSION=9 MYSQL_VERSION=5.7 MONGO_VERSION=3.2 MSSQL_VERSION=2017-GA-ubuntu
- TEST_CMD="make databases test" POSTGRESQL_VERSION=10 MYSQL_VERSION=5.7 MONGO_VERSION=3.6 MSSQL_VERSION=2017-GDR-ubuntu
- TEST_CMD="make databases test" POSTGRESQL_VERSION=11 MYSQL_VERSION=5 MONGO_VERSION=3 MSSQL_VERSION=latest
- TEST_CMD="make benchmark"

notifications:
email: false

language: go

go:
- "1.8"
- "1.9"
# - "tip"
- "1.10"
- "1.11"

services:
- docker
- mongodb
- postgresql

addons:
postgresql: 9.6
apt:
sources:
- mongodb-3.0-precise
packages:
- freetds-bin
- mongodb-org-server
- mongodb-org-shell

before_install:
- sudo service mysql stop
- docker pull microsoft/mssql-server-linux:latest
- docker pull mysql:5.7
- docker run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=my$Password' --name mssql -p 1433:1433 -d microsoft/mssql-server-linux:latest
- docker run -d -e "MYSQL_USER=upperio_tests" -e "MYSQL_PASSWORD=upperio_secret" -e "MYSQL_ALLOW_EMPTY_PASSWORD=1" -e "MYSQL_DATABASE=upperio_tests" -p 3306:3306 --name mysql mysql:5.7
- docker ps -a
- sleep 30

env:
global:
- MAKEFLAGS="-j4"
- GOARCH=amd64
- DB_HOST=127.0.0.1
matrix:
- TEST_CMD="make benchmark test-main"
- TEST_CMD="make test-adapters"
- sudo service mysql stop &
- sudo service postgresql stop &
- sudo apt-get install -y parallel &
- wait

install:
- mkdir -p $GOPATH/src/upper.io
- mv $PWD $GOPATH/src/upper.io/db.v3
- cd $GOPATH/src/upper.io/db.v3
- export TRAVIS_BUILD_DIR=$GOPATH/src/upper.io/db.v3
- mv $PWD $TRAVIS_BUILD_DIR
- cd $TRAVIS_BUILD_DIR
- go get -t -v -d ./...
- go get -v github.com/cznic/ql/ql
- export TRAVIS_BUILD_DIR=$GOPATH/src/upper.io/db.v3

before_script:
- docker exec -it mysql bash -c 'mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql'

script:
- ${TEST_CMD}
- bash -c "$TEST_CMD"
138 changes: 121 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
SHELL := /bin/bash
SHELL := /bin/bash

WAPPER ?= all
DB_HOST ?= 127.0.0.1
POSTGRESQL_IMAGE ?= postgres
POSTGRESQL_VERSION ?= 11
POSTGRESQL_CONTAINER ?= upper-postgresql
POSTGRESQL_PORT ?= 5432

TEST_FLAGS ?=
MYSQL_IMAGE ?= mysql
MYSQL_VERSION ?= 5
MYSQL_CONTAINER ?= upper-mysql
MYSQL_PORT ?= 3306

MONGO_IMAGE ?= mongo
MONGO_VERSION ?= 3
MONGO_CONTAINER ?= upper-mongo
MONGO_PORT ?= 27017

MSSQL_IMAGE ?= mcr.microsoft.com/mssql/server
MSSQL_VERSION ?= latest
MSSQL_CONTAINER ?= upper-mssql
MSSQL_PORT ?= 1433

DB_USERNAME ?= upperio_tests
DB_PASSWORD ?= upperio_secret

BIND_HOST ?= 0.0.0.0

WRAPPER ?= all
DB_HOST ?= 127.0.0.1

TEST_FLAGS ?=

PARALLEL_FLAGS ?= --halt 2 -v

export DB_HOST
export WRAPPER

test: reset-db test-libs test-main test-adapters

benchmark-lib:
go test -v -benchtime=500ms -bench=. ./lib/...

Expand All @@ -22,22 +51,97 @@ test-lib:
test-internal:
go test -v ./internal/...

test-libs: test-lib test-internal
test-libs:
parallel $(PARALLEL_FLAGS) -u \
"$(MAKE) test-{}" ::: \
lib \
internal

test-adapters: test-adapter-postgresql test-adapter-mysql test-adapter-sqlite test-adapter-mssql test-adapter-ql test-adapter-mongo
test-adapters:
parallel $(PARALLEL_FLAGS) -u \
"$(MAKE) test-adapter-{}" ::: \
postgresql \
mysql \
sqlite \
mssql \
ql \
mongo

reset-db:
$(MAKE) -C postgresql reset-db && \
$(MAKE) -C mysql reset-db && \
$(MAKE) -C sqlite reset-db && \
$(MAKE) -C mssql reset-db && \
$(MAKE) -C ql reset-db && \
$(MAKE) -C mongo reset-db

test-main: reset-db
test-main:
go test $(TEST_FLAGS) -v ./tests/...

test: test-adapters test-libs test-main
reset-db:
parallel $(PARALLEL_FLAGS) \
"$(MAKE) reset-db-{}" ::: \
postgresql \
mysql \
sqlite \
mssql \
ql \
mongo

test-adapter-%:
$(MAKE) -C $* test || exit 1;
($(MAKE) -C $* test || exit 1)

reset-db-%:
($(MAKE) -C $* reset-db || exit 1)

databases:
parallel $(PARALLEL_FLAGS) -u \
"$(MAKE) docker-{}" ::: \
postgresql \
mysql \
mssql \
mongo && \
sleep 30

docker-mongo:
docker pull $(MONGO_IMAGE):$(MONGO_VERSION) && \
(docker rm -f $(MONGO_CONTAINER) || exit 0) && \
docker run \
-d \
--rm \
-e "MONGO_USER=$(DB_USERNAME)" \
-e "MONGO_PASSWORD=$(DB_PASSWORD)" \
-e "MONGO_DATABASE=$(DB_USERNAME)" \
-p $(BIND_HOST):$(MONGO_PORT):27017 \
--name $(MONGO_CONTAINER) \
$(MONGO_IMAGE):$(MONGO_VERSION)

docker-mysql:
docker pull $(MYSQL_IMAGE):$(MYSQL_VERSION) && \
(docker rm -f $(MYSQL_CONTAINER) || exit 0) && \
docker run \
-d \
--rm \
-e "MYSQL_USER=$(DB_USERNAME)" \
-e "MYSQL_PASSWORD=$(DB_PASSWORD)" \
-e "MYSQL_ALLOW_EMPTY_PASSWORD=1" \
-e "MYSQL_DATABASE=$(DB_USERNAME)" \
-p $(BIND_HOST):$(MYSQL_PORT):3306 \
--name $(MYSQL_CONTAINER) \
$(MYSQL_IMAGE):$(MYSQL_VERSION)

docker-mssql:
docker pull $(MSSQL_IMAGE):$(MSSQL_VERSION) && \
(docker rm -f $(MSSQL_CONTAINER) || exit 0) && \
docker run \
-d \
--rm \
-e "ACCEPT_EULA=Y" \
-e 'SA_PASSWORD=my$$Password' \
-p $(BIND_HOST):$(MSSQL_PORT):1433 \
--name $(MSSQL_CONTAINER) \
$(MSSQL_IMAGE):$(MSSQL_VERSION)

docker-postgresql:
docker pull $(POSTGRESQL_IMAGE):$(POSTGRESQL_VERSION) && \
(docker rm -f $(POSTGRESQL_CONTAINER) || exit 0) && \
docker run \
-d \
--rm \
-e "POSTGRES_USER=$(DB_USERNAME)" \
-e "POSTGRES_PASSWORD=$(DB_PASSWORD)" \
-p $(BIND_HOST):$(POSTGRESQL_PORT):5432 \
--name $(POSTGRESQL_CONTAINER) \
$(POSTGRESQL_IMAGE):$(POSTGRESQL_VERSION)
2 changes: 1 addition & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *Cache) Clear() {
func Hash(v interface{}) string {
q, err := hashstructure.Hash(v, nil)
if err != nil {
panic(fmt.Sprintf("Could not hash struct: ", err.Error()))
panic(fmt.Sprintf("Could not hash struct: %v", err.Error()))
}
return strconv.FormatUint(q, 10)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/sqladapter/exql/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func (c *Column) Compile(layout *Template) (compiled string, err error) {
if nameChunks[i] == "*" {
continue
}
nameChunks[i] = mustParse(layout.IdentifierQuote, Raw{Value: nameChunks[i]})
nameChunks[i] = layout.MustCompile(layout.IdentifierQuote, Raw{Value: nameChunks[i]})
}

compiled = strings.Join(nameChunks, layout.ColumnSeparator)

if len(chunks) > 1 {
alias = trimString(chunks[1])
alias = mustParse(layout.IdentifierQuote, Raw{Value: alias})
alias = layout.MustCompile(layout.IdentifierQuote, Raw{Value: alias})
}
case Raw:
compiled = value.String()
Expand All @@ -72,7 +72,7 @@ func (c *Column) Compile(layout *Template) (compiled string, err error) {
}

if alias != "" {
compiled = mustParse(layout.ColumnAliasLayout, columnT{compiled, alias})
compiled = layout.MustCompile(layout.ColumnAliasLayout, columnT{compiled, alias})
}

layout.Write(c, compiled)
Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/exql/column_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *ColumnValue) Compile(layout *Template) (compiled string, err error) {
}
}

compiled = strings.TrimSpace(mustParse(layout.ColumnValue, data))
compiled = strings.TrimSpace(layout.MustCompile(layout.ColumnValue, data))

layout.Write(c, compiled)

Expand Down
11 changes: 11 additions & 0 deletions internal/sqladapter/exql/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ func UsingColumns(columns ...Fragment) *Using {
return &Using{Columns: columns}
}

// Append
func (c *Columns) Append(a *Columns) *Columns {
c.Columns = append(c.Columns, a.Columns...)
return c
}

// IsEmpty
func (c *Columns) IsEmpty() bool {
if c == nil || len(c.Columns) < 1 {
return true
}
return false
}

// Compile transforms the Columns into an equivalent SQL representation.
func (c *Columns) Compile(layout *Template) (compiled string, err error) {

Expand All @@ -57,6 +66,8 @@ func (c *Columns) Compile(layout *Template) (compiled string, err error) {
}

compiled = strings.Join(out, layout.IdentifierSeparator)
} else {
compiled = "*"
}

layout.Write(c, compiled)
Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/exql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (d *Database) Compile(layout *Template) (compiled string, err error) {
return c, nil
}

compiled = mustParse(layout.IdentifierQuote, Raw{Value: d.Name})
compiled = layout.MustCompile(layout.IdentifierQuote, Raw{Value: d.Name})

layout.Write(d, compiled)
return
Expand Down
Loading

0 comments on commit 2f58dea

Please sign in to comment.