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

Switch from ory/dockertest to testcontainers #245

Merged
merged 2 commits into from
Mar 12, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
env:
GOFUMPT_VERSION: 0.3.1
GOLANGCI_LINT_VERSION: 1.49.0
GOLANGCI_LINT_VERSION: 1.56.2
jobs:
linux:
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ linters:
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- durationcheck
Expand Down Expand Up @@ -37,6 +36,8 @@ linters:
- predeclared
- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagliatelle
Expand All @@ -46,9 +47,11 @@ linters:
- unconvert
- unparam
- unused
- wastedassign
- whitespace
disable:
- cyclop
- depguard
- exhaustive
- exhaustivestruct
- funlen
Expand All @@ -63,10 +66,7 @@ linters:
- nestif
- nlreturn
- paralleltest
- rowserrcheck # https://github.com/golangci/golangci-lint/issues/2649
- sqlclosecheck # https://github.com/golangci/golangci-lint/issues/2649
- testpackage
- wastedassign # https://github.com/golangci/golangci-lint/issues/2649
- wrapcheck
- wsl

Expand Down
2 changes: 1 addition & 1 deletion encoding/geojson/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func EncodeGeometryWithBBox() EncodeGeometryOption {
// EncodeGeometryWithCRS adds the crs field to the Geometry GeoJSON encoding.
func EncodeGeometryWithCRS(crs *CRS) EncodeGeometryOption {
return EncodeGeometryOption{
onGeometryHandler: func(g *Geometry, t geom.T, opts ...EncodeGeometryOption) error {
onGeometryHandler: func(g *Geometry, _ geom.T, _ ...EncodeGeometryOption) error {
var err error
g.CRS = crs
return err
Expand Down
1 change: 1 addition & 0 deletions encoding/wkb/sql_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func Example_value_different_shapes() {
}

for _, s := range shapes {
s := s
result, err := db.Exec(`INSERT INTO objects (name, location) VALUES (?, ?);`, s.Name, &s.Geom)
if err != nil {
log.Fatal(err)
Expand Down
57 changes: 34 additions & 23 deletions examples/postgis/main_test.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
//go:build docker
// +build docker
//go:build !windows

package main

import (
"bytes"
"context"
"database/sql"
"fmt"
"os/exec"
"strings"
"testing"
"time"

"github.com/alecthomas/assert/v2"
_ "github.com/lib/pq"
"github.com/ory/dockertest/v3"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/wait"
)

func TestMain(t *testing.T) {
func TestIntegration(t *testing.T) {
ctx := context.Background()

if _, err := exec.LookPath("docker"); err != nil {
t.Skip("docker not found in $PATH")
}

var (
dbName = "testdb"
database = "testdb"
user = "testuser"
password = "testpassword"
)

pool, err := dockertest.NewPool("")
pgContainer, err := postgres.RunContainer(ctx,
testcontainers.WithImage("docker.io/postgis/postgis:16-3.4"),
postgres.WithDatabase(database),
postgres.WithUsername(user),
postgres.WithPassword(password),
testcontainers.WithWaitStrategy(
wait.ForLog("database system is ready to accept connections").
WithOccurrence(2).
WithStartupTimeout(5*time.Second),
),
)
assert.NoError(t, err)

resource, err := pool.Run("mdillon/postgis", "latest", []string{
"POSTGRES_DB=" + dbName,
"POSTGRES_PASSWORD=" + password,
"POSTGRES_USER=" + user,
t.Cleanup(func() {
assert.NoError(t, pgContainer.Terminate(ctx))
})

connStr, err := pgContainer.ConnectionString(ctx, "binary_parameters=yes", "sslmode=disable")
assert.NoError(t, err)

db, err := sql.Open("postgres", connStr)
assert.NoError(t, err)
defer func() {
assert.NoError(t, pool.Purge(resource))
assert.NoError(t, db.Close())
}()

var db *sql.DB
assert.NoError(t, pool.Retry(func() error {
dsn := fmt.Sprintf("postgres://%s:%s@localhost:%s/%s?binary_parameters=yes&sslmode=disable", user, password, resource.GetPort("5432/tcp"), dbName)
var err error
db, err = sql.Open("postgres", dsn)
if err != nil {
return err
}
return db.Ping()
}))

assert.NoError(t, createDB(db))

assert.NoError(t, populateDB(db))
Expand Down
74 changes: 49 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
module github.com/twpayne/go-geom

go 1.19
go 1.21

toolchain go1.22.1

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/alecthomas/assert/v2 v2.4.0
github.com/lib/pq v1.10.9
github.com/ory/dockertest/v3 v3.9.1
github.com/testcontainers/testcontainers-go v0.29.1
github.com/testcontainers/testcontainers-go/modules/postgres v0.29.1
github.com/twpayne/go-kml/v3 v3.1.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/alecthomas/repr v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/docker/cli v20.10.17+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.12 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading
Loading