Skip to content

Commit

Permalink
Merge pull request #513 from upper/hotfix/refactor-tests-layout
Browse files Browse the repository at this point in the history
Refactor test suite
  • Loading branch information
xiam authored Aug 14, 2019
2 parents ff77bee + cd7b3bd commit 86a33f5
Show file tree
Hide file tree
Showing 96 changed files with 5,170 additions and 3,494 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ env:
- GOARCH=amd64
- DB_HOST=127.0.0.1
matrix:
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=9 MYSQL_VERSION=5.7 MONGO_VERSION=3.2 MSSQL_VERSION=2017-GA-ubuntu
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=10 MYSQL_VERSION=5.7 MONGO_VERSION=3.6 MSSQL_VERSION=2017-GDR-ubuntu
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=11 MYSQL_VERSION=5 MONGO_VERSION=3 MSSQL_VERSION=latest
- TEST_CMD="make test"
- TEST_CMD="make benchmark"

notifications:
Expand Down
76 changes: 17 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
SHELL := /bin/bash

MONGO_VERSION ?= 3
MYSQL_VERSION ?= 5
POSTGRES_VERSION ?= 11
MSSQL_VERSION ?= 2017-latest-ubuntu

DB_NAME ?= upperio
DB_USERNAME ?= upperio_user
DB_PASSWORD ?= upperio//s3cr37

BIND_HOST ?= 127.0.0.1

WRAPPER ?= all
DB_HOST ?= 127.0.0.1
PARALLEL_FLAGS ?= --halt now,fail=1 --jobs=2 -v -u

TEST_FLAGS ?=

PARALLEL_FLAGS ?= --halt 2 -v

export MONGO_VERSION
export MYSQL_VERSION
export POSTGRES_VERSION
export MSSQL_VERSION

export DB_USERNAME
export DB_PASSWORD
export DB_NAME
export DB_HOST

export BIND_HOST
export WRAPPER
export TEST_FLAGS
export PARALLEL_FLAGS

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

benchmark-lib:
go test -v -benchtime=500ms -bench=. ./lib/...
Expand All @@ -48,43 +24,25 @@ test-internal:
go test -v ./internal/...

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

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

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

reset-db:
parallel $(PARALLEL_FLAGS) \
"$(MAKE) reset-db-{}" ::: \
postgresql \
mysql \
sqlite \
mssql \
ql \
mongo
for MAKEFILE in $$(grep -Rl test-extended */Makefile | sort -u); do \
ADAPTER=$$(dirname $$MAKEFILE); \
($(MAKE) test-adapter-$$ADAPTER || exit 1); \
done

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

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

db-up:
docker-compose -p upper up -d && \
sleep 15
test-generic:
export TEST_FLAGS="-run TestGeneric"; \
$(MAKE) test-adapters

db-down:
docker-compose -p upper down
goimports:
for FILE in $$(find -name "*.go" | grep -v vendor); do \
goimports -w $$FILE; \
done
18 changes: 9 additions & 9 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ package db
// Collection is an interface that defines methods useful for handling tables.
type Collection interface {
// Insert inserts a new item into the collection, it accepts one argument
// that can be either a map or a struct. If the call suceeds, it returns the
// ID of the newly added element as an `interface{}` (the underlying type of
// this ID is unknown and depends on the database adapter). The ID returned
// by Insert() could be passed directly to Find() to retrieve the newly added
// element.
// that can be either a map or a struct. If the call succeeds, it returns the
// ID of the newly added element as an `interface{}` (the actual type of this
// ID depends on both the database adapter and the column that stores this
// ID). The ID returned by Insert() could be passed directly to Find() to
// retrieve the newly added element.
Insert(interface{}) (interface{}, error)

// InsertReturning is like Insert() but it updates the passed pointer to map
// or struct with the newly inserted element (and with automatic fields, like
// IDs, timestamps, etc). This is all done atomically within a transaction.
// If the database does not support transactions this method returns
// InsertReturning is like Insert() but it updates the passed map or struct
// with the newly inserted element (and with automatic fields, like IDs,
// timestamps, etc). This is all done atomically within a transaction. If
// the database does not support transactions this method returns
// db.ErrUnsupported.
InsertReturning(interface{}) error

Expand Down
2 changes: 1 addition & 1 deletion comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,4 @@ func toInterfaceArray(v interface{}) []interface{} {
return []interface{}{v}
}

var _ Comparison = &dbComparisonOperator{}
var _ = Comparison(&dbComparisonOperator{})
10 changes: 6 additions & 4 deletions compound.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
)

// Compound represents an statement that has one or many sentences joined by by
// an operator like "AND" or "OR". This is an exported interface but it's
// rarely used directly, you may want to use the `db.And()` or `db.Or()`
// an operator like "AND" or "OR". This is an exported interface but it was
// designed for internal usage, you may want to use the `db.And()` or `db.Or()`
// functions instead.
type Compound interface {
// Sentences returns child sentences.
Expand Down Expand Up @@ -125,5 +125,7 @@ func defaultJoin(in ...Compound) []Compound {
return in
}

var _ = immutable.Immutable(&compound{})
var _ Compound = Cond{}
var (
_ = immutable.Immutable(&compound{})
_ = Compound(Cond{})
)
2 changes: 1 addition & 1 deletion cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// Each entry of the map represents a condition (a column-value relation bound
// by a comparison operator). The comparison operator is optional and can be
// specified after the column name, if no comparison operator is provided the
// equality is used.
// equality operator is used as default.
//
// Examples:
//
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewConstraint(key interface{}, value interface{}) Constraint {
return constraint{k: key, v: value}
}

var _ Constraints = Cond{}

var _ Constraint = &constraint{}
var (
_ = Constraints(Cond{})
_ = Constraint(&constraint{})
)
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package db
// Database is an interface that defines methods that must be satisfied by
// all database adapters.
type Database interface {
// Driver returns the underlying driver the wrapper uses.
// Driver returns the underlying driver the wrapper uses as an interface{}.
//
// In order to actually use the driver, the `interface{}` value needs to be
// casted into the appropriate type.
Expand Down
9 changes: 3 additions & 6 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Package db (or upper-db) provides a common interface to work with different
// data sources using adapters that wrap mature database drivers.
// Package db (or upper-db) provides a common interface to work with a variety
// of data sources using adapters that wrap mature database drivers.
//
// The main purpose of upper-db is to abstract common database operations and
// encourage users perform advanced operations directly using the underlying
// driver. upper-db supports the MySQL, PostgreSQL, SQLite and QL databases and
// provides partial support (CRUD, no transactions) for MongoDB.
// Install upper-db:
//
// go get upper.io/db.v3
//
Expand Down
40 changes: 0 additions & 40 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// Error messages.
var (
ErrNoMoreRows = errors.New(`upper: no more rows in this result set`)
ErrNotConnected = errors.New(`upper: you're currently not connected`)
ErrNotConnected = errors.New(`upper: not connected to a database`)
ErrMissingDatabaseName = errors.New(`upper: missing database name`)
ErrMissingCollectionName = errors.New(`upper: missing collection name`)
ErrCollectionDoesNotExist = errors.New(`upper: collection does not exist`)
Expand Down
2 changes: 1 addition & 1 deletion function.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ func (f *dbFunc) Name() string {
return f.name
}

var _ Function = &dbFunc{}
var _ = Function(&dbFunc{})
2 changes: 1 addition & 1 deletion internal/sqladapter/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"reflect"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/sqladapter/exql"
"upper.io/db.v3/lib/reflectx"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync/atomic"
"time"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/cache"
"upper.io/db.v3/internal/sqladapter/compat"
"upper.io/db.v3/internal/sqladapter/exql"
Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/exql/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"text/template"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/cache"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sync"
"sync/atomic"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/immutable"
"upper.io/db.v3/lib/sqlbuilder"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/sqladapter/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"database/sql"
"sync/atomic"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/lib/sqlbuilder"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"strconv"
"strings"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/sqladapter/compat"
"upper.io/db.v3/internal/sqladapter/exql"
"upper.io/db.v3/lib/reflectx"
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"upper.io/db.v3"
db "upper.io/db.v3"
)

func TestSelect(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/sqladapter/exql"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"strings"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/sqladapter/exql"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package sqlbuilder
import (
"reflect"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/lib/reflectx"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math"
"strings"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/immutable"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/placeholder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"upper.io/db.v3"
db "upper.io/db.v3"
)

func TestPlaceholderSimple(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package sqlbuilder
import (
"database/sql"

"upper.io/db.v3"
db "upper.io/db.v3"
)

type scanner struct {
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlbuilder/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"upper.io/db.v3"
db "upper.io/db.v3"
"upper.io/db.v3/internal/immutable"
"upper.io/db.v3/internal/sqladapter/exql"
)
Expand Down
Loading

0 comments on commit 86a33f5

Please sign in to comment.