Skip to content

Commit 86a33f5

Browse files
authored
Merge pull request #513 from upper/hotfix/refactor-tests-layout
Refactor test suite
2 parents ff77bee + cd7b3bd commit 86a33f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5170
-3494
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ env:
99
- GOARCH=amd64
1010
- DB_HOST=127.0.0.1
1111
matrix:
12-
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=9 MYSQL_VERSION=5.7 MONGO_VERSION=3.2 MSSQL_VERSION=2017-GA-ubuntu
13-
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=10 MYSQL_VERSION=5.7 MONGO_VERSION=3.6 MSSQL_VERSION=2017-GDR-ubuntu
14-
- TEST_CMD="make db-up test" POSTGRESQL_VERSION=11 MYSQL_VERSION=5 MONGO_VERSION=3 MSSQL_VERSION=latest
12+
- TEST_CMD="make test"
1513
- TEST_CMD="make benchmark"
1614

1715
notifications:

Makefile

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
11
SHELL := /bin/bash
22

3-
MONGO_VERSION ?= 3
4-
MYSQL_VERSION ?= 5
5-
POSTGRES_VERSION ?= 11
6-
MSSQL_VERSION ?= 2017-latest-ubuntu
7-
8-
DB_NAME ?= upperio
9-
DB_USERNAME ?= upperio_user
10-
DB_PASSWORD ?= upperio//s3cr37
11-
12-
BIND_HOST ?= 127.0.0.1
13-
14-
WRAPPER ?= all
15-
DB_HOST ?= 127.0.0.1
3+
PARALLEL_FLAGS ?= --halt now,fail=1 --jobs=2 -v -u
164

175
TEST_FLAGS ?=
186

19-
PARALLEL_FLAGS ?= --halt 2 -v
20-
21-
export MONGO_VERSION
22-
export MYSQL_VERSION
23-
export POSTGRES_VERSION
24-
export MSSQL_VERSION
25-
26-
export DB_USERNAME
27-
export DB_PASSWORD
28-
export DB_NAME
29-
export DB_HOST
30-
31-
export BIND_HOST
32-
export WRAPPER
7+
export TEST_FLAGS
8+
export PARALLEL_FLAGS
339

34-
test: reset-db test-libs test-main test-adapters
10+
test: test-libs test-adapters
3511

3612
benchmark-lib:
3713
go test -v -benchtime=500ms -bench=. ./lib/...
@@ -48,43 +24,25 @@ test-internal:
4824
go test -v ./internal/...
4925

5026
test-libs:
51-
parallel $(PARALLEL_FLAGS) -u \
27+
parallel $(PARALLEL_FLAGS) \
5228
"$(MAKE) test-{}" ::: \
5329
lib \
5430
internal
5531

5632
test-adapters:
57-
parallel $(PARALLEL_FLAGS) -u \
58-
"$(MAKE) test-adapter-{}" ::: \
59-
postgresql \
60-
mysql \
61-
sqlite \
62-
mssql \
63-
ql \
64-
mongo
65-
66-
test-main:
67-
go test $(TEST_FLAGS) -v ./tests/...
68-
69-
reset-db:
70-
parallel $(PARALLEL_FLAGS) \
71-
"$(MAKE) reset-db-{}" ::: \
72-
postgresql \
73-
mysql \
74-
sqlite \
75-
mssql \
76-
ql \
77-
mongo
33+
for MAKEFILE in $$(grep -Rl test-extended */Makefile | sort -u); do \
34+
ADAPTER=$$(dirname $$MAKEFILE); \
35+
($(MAKE) test-adapter-$$ADAPTER || exit 1); \
36+
done
7837

7938
test-adapter-%:
80-
($(MAKE) -C $* test || exit 1)
81-
82-
reset-db-%:
83-
($(MAKE) -C $* reset-db || exit 1)
39+
($(MAKE) -C $* test-extended || exit 1)
8440

85-
db-up:
86-
docker-compose -p upper up -d && \
87-
sleep 15
41+
test-generic:
42+
export TEST_FLAGS="-run TestGeneric"; \
43+
$(MAKE) test-adapters
8844

89-
db-down:
90-
docker-compose -p upper down
45+
goimports:
46+
for FILE in $$(find -name "*.go" | grep -v vendor); do \
47+
goimports -w $$FILE; \
48+
done

collection.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ package db
2424
// Collection is an interface that defines methods useful for handling tables.
2525
type Collection interface {
2626
// Insert inserts a new item into the collection, it accepts one argument
27-
// that can be either a map or a struct. If the call suceeds, it returns the
28-
// ID of the newly added element as an `interface{}` (the underlying type of
29-
// this ID is unknown and depends on the database adapter). The ID returned
30-
// by Insert() could be passed directly to Find() to retrieve the newly added
31-
// element.
27+
// that can be either a map or a struct. If the call succeeds, it returns the
28+
// ID of the newly added element as an `interface{}` (the actual type of this
29+
// ID depends on both the database adapter and the column that stores this
30+
// ID). The ID returned by Insert() could be passed directly to Find() to
31+
// retrieve the newly added element.
3232
Insert(interface{}) (interface{}, error)
3333

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

comparison.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,4 @@ func toInterfaceArray(v interface{}) []interface{} {
331331
return []interface{}{v}
332332
}
333333

334-
var _ Comparison = &dbComparisonOperator{}
334+
var _ = Comparison(&dbComparisonOperator{})

compound.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
)
2727

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

128-
var _ = immutable.Immutable(&compound{})
129-
var _ Compound = Cond{}
128+
var (
129+
_ = immutable.Immutable(&compound{})
130+
_ = Compound(Cond{})
131+
)

cond.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
// Each entry of the map represents a condition (a column-value relation bound
3333
// by a comparison operator). The comparison operator is optional and can be
3434
// specified after the column name, if no comparison operator is provided the
35-
// equality is used.
35+
// equality operator is used as default.
3636
//
3737
// Examples:
3838
//
File renamed without changes.

constraint.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func NewConstraint(key interface{}, value interface{}) Constraint {
6161
return constraint{k: key, v: value}
6262
}
6363

64-
var _ Constraints = Cond{}
65-
66-
var _ Constraint = &constraint{}
64+
var (
65+
_ = Constraints(Cond{})
66+
_ = Constraint(&constraint{})
67+
)

database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package db
2424
// Database is an interface that defines methods that must be satisfied by
2525
// all database adapters.
2626
type Database interface {
27-
// Driver returns the underlying driver the wrapper uses.
27+
// Driver returns the underlying driver the wrapper uses as an interface{}.
2828
//
2929
// In order to actually use the driver, the `interface{}` value needs to be
3030
// casted into the appropriate type.

db.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2020
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
// Package db (or upper-db) provides a common interface to work with different
23-
// data sources using adapters that wrap mature database drivers.
22+
// Package db (or upper-db) provides a common interface to work with a variety
23+
// of data sources using adapters that wrap mature database drivers.
2424
//
25-
// The main purpose of upper-db is to abstract common database operations and
26-
// encourage users perform advanced operations directly using the underlying
27-
// driver. upper-db supports the MySQL, PostgreSQL, SQLite and QL databases and
28-
// provides partial support (CRUD, no transactions) for MongoDB.
25+
// Install upper-db:
2926
//
3027
// go get upper.io/db.v3
3128
//

0 commit comments

Comments
 (0)