Skip to content

Commit 719cf28

Browse files
authored
tests: refactor test suite and move them to their own directory. (#727)
1 parent b9a2b5f commit 719cf28

Some content is hidden

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

58 files changed

+1248
-2455
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ jobs:
2626
with:
2727
go-version: ${{ matrix.go-version }}
2828

29-
- name: Set env vars
29+
- name: Configure environment
3030
run: |
3131
echo "GOARCH=amd64" >> $GITHUB_ENV
3232
echo "DB_HOST=127.0.0.1" >> $GITHUB_ENV
3333
echo "UPPER_DB_LOG=ERROR" >> $GITHUB_ENV
3434
35-
- name: Run target
35+
- name: Run tests
3636
run: make test

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*.sw?
22
*.db
33
*.tmp
4-
generated_*.go
4+
.venv

Makefile

+5-39
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
1-
SHELL ?= bash
2-
CPU_CORES ?= $(shell nproc)
1+
UPPER_DB_LOG ?= ERROR
32

4-
PARALLEL_FLAGS ?= --halt-on-error 2 --jobs=$(CPU_CORES) -v -u
5-
6-
TEST_FLAGS ?= -v -failfast -race -timeout 20m
7-
8-
UPPER_DB_LOG ?= WARN
9-
10-
export TEST_FLAGS
11-
export PARALLEL_FLAGS
123
export UPPER_DB_LOG
134

14-
test: go-test-internal test-adapters
15-
16-
benchmark: go-benchmark-internal
17-
18-
go-benchmark-%:
19-
go test -v -benchtime=500ms -bench=. ./$*/...
20-
21-
go-test-%:
22-
go test -v ./$*/...
23-
24-
test-adapters: \
25-
test-adapter-postgresql \
26-
test-adapter-cockroachdb \
27-
test-adapter-mysql \
28-
test-adapter-mssql \
29-
test-adapter-sqlite \
30-
test-adapter-ql \
31-
test-adapter-mongo
32-
33-
test-adapter-%:
34-
($(MAKE) -C adapter/$* test-extended || exit 1)
35-
36-
test-generic:
37-
export TEST_FLAGS="-run TestGeneric"; \
38-
$(MAKE) test-adapters
5+
bench:
6+
go test -v -benchtime=500ms -bench=. ./internal/...
397

40-
goimports:
41-
for FILE in $$(find -name "*.go" | grep -v vendor); do \
42-
goimports -w $$FILE; \
43-
done
8+
test:
9+
$(MAKE) -C tests

adapter/cockroachdb/Makefile

-49
This file was deleted.

adapter/cockroachdb/docker-compose.yml

-9
This file was deleted.

adapter/cockroachdb/generic_test.go

-41
This file was deleted.

adapter/cockroachdb/record_test.go

-41
This file was deleted.

adapter/cockroachdb/sql_test.go

-41
This file was deleted.

adapter/mongo/Makefile

-43
This file was deleted.

adapter/mongo/collection.go

-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ package mongo
2424
import (
2525
"context"
2626
"fmt"
27-
"reflect"
2827
"strings"
29-
"sync"
3028

3129
db "github.com/upper/db/v4"
3230
"github.com/upper/db/v4/internal/adapter"
@@ -40,13 +38,6 @@ type Collection struct {
4038
collection *mongo.Collection
4139
}
4240

43-
var (
44-
// idCache should be a struct if we're going to cache more than just
45-
// _id field here
46-
idCache = make(map[reflect.Type]string)
47-
idCacheMutex sync.RWMutex
48-
)
49-
5041
// Find creates a result set with the given conditions.
5142
func (col *Collection) Find(terms ...interface{}) db.Result {
5243
fields := []string{"*"}

adapter/mongo/connection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func ParseURL(s string) (conn ConnectionURL, err error) {
9797
}
9898

9999
if u, err = url.Parse(s); err != nil {
100-
return conn, fmt.Errorf("invalid URL: %v", err)
100+
return conn, fmt.Errorf("invalid URL: %w", err)
101101
}
102102

103103
conn.Scheme = u.Scheme
@@ -118,7 +118,7 @@ func ParseURL(s string) (conn ConnectionURL, err error) {
118118
var vv url.Values
119119

120120
if vv, err = url.ParseQuery(u.RawQuery); err != nil {
121-
return conn, fmt.Errorf("invalid query: %v", err)
121+
return conn, fmt.Errorf("invalid query: %w", err)
122122
}
123123

124124
for k := range vv {

adapter/mongo/database.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (s *Source) open() error {
178178
}
179179

180180
s.collections = map[string]*Collection{}
181-
s.database = s.session.Database(settings.Database)
181+
s.database = s.session.Database(s.connURL.(ConnectionURL).Database)
182182

183183
// ping
184184
if err = s.Ping(); err != nil {
@@ -191,7 +191,7 @@ func (s *Source) open() error {
191191
// Close terminates the current database session.
192192
func (s *Source) Close() error {
193193
if s.session != nil {
194-
s.session.Disconnect(context.Background())
194+
return s.session.Disconnect(context.Background())
195195
}
196196

197197
return nil

adapter/mongo/docker-compose.yml

-11
This file was deleted.

0 commit comments

Comments
 (0)