Skip to content

Commit

Permalink
Refactor test suite (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Feb 1, 2022
1 parent 5da30ca commit 7aebaad
Show file tree
Hide file tree
Showing 30 changed files with 309 additions and 492 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
jobs:
lint:
name: lint
strategy:
fail-fast: false
matrix:
module: [ ".", "tests/suite", "tests/mysql", "tests/postgres" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -20,7 +24,7 @@ jobs:
version: v1.43.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
working-directory: ${{ matrix.module }}

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-compatibility-libpq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ jobs:
id: test
env:
GOARCH: ${{ matrix.arch }}
COMPATIBILITY_TEST: postgres
POSTGRES_VERSION: ${{ matrix.postgres-version }}-alpine
POSTGRES_DRIVER: postgres
run: |
make test-compatibility
make test-compatibility-postgres
3 changes: 1 addition & 2 deletions .github/workflows/test-compatibility-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
id: test
env:
GOARCH: ${{ matrix.arch }}
COMPATIBILITY_TEST: mysql
MYSQL_VERSION: ${{ matrix.mysql-version }}
run: |
make test-compatibility
make test-compatibility-mysql
3 changes: 1 addition & 2 deletions .github/workflows/test-compatibility-pgx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ jobs:
id: test
env:
GOARCH: ${{ matrix.arch }}
COMPATIBILITY_TEST: postgres
POSTGRES_VERSION: ${{ matrix.postgres-version }}-alpine
POSTGRES_DRIVER: pgx
run: |
make test-compatibility
make test-compatibility-postgres
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linters:
- gci
- gochecknoglobals
- golint
- gomoddirectives
- gomnd
- goerr113
- ifshort
Expand Down
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,37 @@ ifeq ($(GOARCH), 386)
TEST_FLAGS =
endif

.PHONY: $(VENDOR_DIR) lint test test-unit test-compatibility
goModules := $(shell find . -name 'go.mod' | xargs dirname)
lintGoModules := $(subst -.,-module,$(subst /,-,$(addprefix lint-,$(goModules))))
compatibilityTests := $(addprefix test-compatibility-,$(filter-out suite,$(subst ./,,$(shell cd tests;find . -name 'go.mod' | xargs dirname))))

.PHONY: $(VENDOR_DIR) $(lintGoModules) $(compatibilityTests) lint test test-unit test-compatibility

$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
@$(GO) mod vendor
@$(GO) mod tidy

lint:
@$(GOLANGCI_LINT) run
@$(GHERKIN_LINT) -c tests/.gherkin-lintrc tests/features/*
$(lintGoModules):
$(eval GO_MODULE := "$(subst lint/module,.,$(subst -,/,$(subst lint-module-,,$@)))")

@echo ">> module: $(GO_MODULE)"
@cd "$(GO_MODULE)"; $(GOLANGCI_LINT) run

test: test-unit
lint: $(lintGoModules)

test: test-unit test-compatibility

## Run unit tests
test-unit:
@echo ">> unit test"
@$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic $(TEST_FLAGS) ./...

test-compatibility:
@echo ">> compatibility test"
@echo ">> COMPATIBILITY_TEST = $(COMPATIBILITY_TEST)"
@echo

$(compatibilityTests):
$(eval COMPATIBILITY_TEST := "$(subst test-compatibility-,,$@)")
@echo ">> compatibility test: $(COMPATIBILITY_TEST)"
@cd "tests/$(COMPATIBILITY_TEST)"; $(GO) test -gcflags=-l -v ./...
@echo

test-compatibility: $(compatibilityTests)
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
go.opentelemetry.io/otel/internal/metric v0.26.0 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -125,11 +126,15 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
2 changes: 2 additions & 0 deletions tests/mysql/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package mysql provides compatibility tests for mysql driver.
package mysql
13 changes: 7 additions & 6 deletions tests/mysql/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ require (
github.com/golang-migrate/migrate/v4 v4.15.1
github.com/nhatthm/go-clock v0.6.0
github.com/nhatthm/otelsql/tests/suite v0.0.0
github.com/testcontainers/testcontainers-go v0.12.0
github.com/nhatthm/testcontainers-go-extra v0.1.0
github.com/nhatthm/testcontainers-go-registry v0.2.0
)

require (
Expand Down Expand Up @@ -50,7 +51,6 @@ require (
github.com/jmoiron/sqlx v1.3.4 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/moby/sys/mount v0.3.0 // indirect
Expand All @@ -64,7 +64,7 @@ require (
github.com/opencontainers/runc v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -74,6 +74,7 @@ require (
github.com/stretchr/testify v1.7.0 // indirect
github.com/swaggest/assertjson v1.6.8 // indirect
github.com/swaggest/form/v5 v5.0.1 // indirect
github.com/testcontainers/testcontainers-go v0.12.0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
go.opencensus.io v0.23.0 // indirect
Expand All @@ -86,9 +87,9 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.26.0 // indirect
go.opentelemetry.io/otel/trace v1.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 7aebaad

Please sign in to comment.