Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor test suite #727

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: Set env vars
- name: Configure environment
run: |
echo "GOARCH=amd64" >> $GITHUB_ENV
echo "DB_HOST=127.0.0.1" >> $GITHUB_ENV
echo "UPPER_DB_LOG=ERROR" >> $GITHUB_ENV

- name: Run target
- name: Run tests
run: make test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.sw?
*.db
*.tmp
generated_*.go
.venv
44 changes: 5 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,9 @@
SHELL ?= bash
CPU_CORES ?= $(shell nproc)
UPPER_DB_LOG ?= ERROR

PARALLEL_FLAGS ?= --halt-on-error 2 --jobs=$(CPU_CORES) -v -u

TEST_FLAGS ?= -v -failfast -race -timeout 20m

UPPER_DB_LOG ?= WARN

export TEST_FLAGS
export PARALLEL_FLAGS
export UPPER_DB_LOG

test: go-test-internal test-adapters

benchmark: go-benchmark-internal

go-benchmark-%:
go test -v -benchtime=500ms -bench=. ./$*/...

go-test-%:
go test -v ./$*/...

test-adapters: \
test-adapter-postgresql \
test-adapter-cockroachdb \
test-adapter-mysql \
test-adapter-mssql \
test-adapter-sqlite \
test-adapter-ql \
test-adapter-mongo

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

test-generic:
export TEST_FLAGS="-run TestGeneric"; \
$(MAKE) test-adapters
bench:
go test -v -benchtime=500ms -bench=. ./internal/...

goimports:
for FILE in $$(find -name "*.go" | grep -v vendor); do \
goimports -w $$FILE; \
done
test:
$(MAKE) -C tests
49 changes: 0 additions & 49 deletions adapter/cockroachdb/Makefile

This file was deleted.

9 changes: 0 additions & 9 deletions adapter/cockroachdb/docker-compose.yml

This file was deleted.

41 changes: 0 additions & 41 deletions adapter/cockroachdb/generic_test.go

This file was deleted.

41 changes: 0 additions & 41 deletions adapter/cockroachdb/record_test.go

This file was deleted.

41 changes: 0 additions & 41 deletions adapter/cockroachdb/sql_test.go

This file was deleted.

43 changes: 0 additions & 43 deletions adapter/mongo/Makefile

This file was deleted.

9 changes: 0 additions & 9 deletions adapter/mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ package mongo
import (
"context"
"fmt"
"reflect"
"strings"
"sync"

db "github.com/upper/db/v4"
"github.com/upper/db/v4/internal/adapter"
Expand All @@ -40,13 +38,6 @@ type Collection struct {
collection *mongo.Collection
}

var (
// idCache should be a struct if we're going to cache more than just
// _id field here
idCache = make(map[reflect.Type]string)
idCacheMutex sync.RWMutex
)

// Find creates a result set with the given conditions.
func (col *Collection) Find(terms ...interface{}) db.Result {
fields := []string{"*"}
Expand Down
4 changes: 2 additions & 2 deletions adapter/mongo/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func ParseURL(s string) (conn ConnectionURL, err error) {
}

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

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

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

for k := range vv {
Expand Down
4 changes: 2 additions & 2 deletions adapter/mongo/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *Source) open() error {
}

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

// ping
if err = s.Ping(); err != nil {
Expand All @@ -191,7 +191,7 @@ func (s *Source) open() error {
// Close terminates the current database session.
func (s *Source) Close() error {
if s.session != nil {
s.session.Disconnect(context.Background())
return s.session.Disconnect(context.Background())
}

return nil
Expand Down
11 changes: 0 additions & 11 deletions adapter/mongo/docker-compose.yml

This file was deleted.

Loading