Skip to content

Commit

Permalink
feat: add initial project infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Feb 5, 2024
1 parent 2d96fec commit 01be1c1
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 15 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: main
on:
pull_request:
push:
branches:
- master
tags:
- v*
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: install-postgis
run: |
sudo apt-get install -y postgis postgresql
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9
- run: go build ./...
- run: go test -v ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9
- uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
with:
version: v1.52.2
144 changes: 144 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- interfacebloat
- ireturn
- loggercheck
- makezero
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagliatelle
- tenv
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
disable:
- cyclop
- depguard
- exhaustivestruct
- exhaustruct
- funlen
- gochecknoglobals
- gochecknoinits
- godox
- gomnd
- lll
- maintidx
- nlreturn
- nonamedreturns
- paralleltest
- structcheck # https://github.com/golangci/golangci-lint/issues/2649
- testableexamples
- varnamelen
- wrapcheck
- wsl

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/twpayne/pgx-geos)
gofumpt:
extra-rules: true
local-prefixes: github.com/twpayne/pgx-geos
goimports:
local-prefixes: github.com/twpayne/pgx-geos
govet:
disable:
- fieldalignment
- shadow
enable-all: true
ireturn:
allow:
- error
- github.com/jackc/pgx/v5/pgtype.EncodePlan
- github.com/jackc/pgx/v5/pgtype.ScanPlan
- stdlib
misspell:
locale: US
stylecheck:
checks:
- all

issues:
exclude-rules:
- linters:
- dupl
- forcetypeassert
- scopelint
path: "_test\\.go"
- linters:
- forbidigo
- gosec
path: "internal/"
- linters:
- goerr113
text: do not define dynamic errors, use wrapped static errors instead
- linters:
- revive
text: unused-parameter
34 changes: 19 additions & 15 deletions pgxgeos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ var defaultConnTestRunner pgxtest.ConnTestRunner

func init() {
defaultConnTestRunner = pgxtest.DefaultConnTestRunner()
defaultConnTestRunner.AfterConnect = func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
defaultConnTestRunner.AfterConnect = func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
_, err := conn.Exec(ctx, "create extension if not exists postgis")
assert.NoError(t, err)
assert.NoError(t, pgxgeos.Register(ctx, conn, geos.NewContext()))
assert.NoError(tb, err)
assert.NoError(tb, pgxgeos.Register(ctx, conn, geos.NewContext()))
}
}

func TestCodecDecodeValue(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
for _, format := range []int16{
pgx.BinaryFormatCode,
pgx.TextFormatCode,
} {
t.(*testing.T).Run(strconv.Itoa(int(format)), func(t *testing.T) {
tb.(*testing.T).Run(strconv.Itoa(int(format)), func(t *testing.T) {
original := mustNewGeomFromWKT(t, "POINT(1 2)").SetSRID(4326)
rows, err := conn.Query(ctx, "select $1::geometry", pgx.QueryResultFormats{format}, original)
assert.NoError(t, err)
Expand All @@ -52,27 +54,29 @@ func TestCodecDecodeValue(t *testing.T) {
}

func TestCodecDecodeNullValue(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
rows, err := conn.Query(ctx, "select $1::geometry", nil)
assert.NoError(t, err)
assert.NoError(tb, err)

for rows.Next() {
values, err := rows.Values()
assert.NoError(t, err)
assert.Equal(t, []any{nil}, values)
assert.NoError(tb, err)
assert.Equal(tb, []any{nil}, values)
}

assert.NoError(t, rows.Err())
assert.NoError(tb, rows.Err())
})
}

func TestCodecScanValue(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
for _, format := range []int16{
pgx.BinaryFormatCode,
pgx.TextFormatCode,
} {
t.(*testing.T).Run(strconv.Itoa(int(format)), func(t *testing.T) {
tb.(*testing.T).Run(strconv.Itoa(int(format)), func(t *testing.T) {
var geom *geos.Geom
err := conn.QueryRow(ctx, "select ST_SetSRID('POINT(1 2)'::geometry, 4326)", pgx.QueryResultFormats{format}).Scan(&geom)
assert.NoError(t, err)
Expand All @@ -82,9 +86,9 @@ func TestCodecScanValue(t *testing.T) {
})
}

func mustNewGeomFromWKT(t testing.TB, wkt string) *geos.Geom {
t.Helper()
func mustNewGeomFromWKT(tb testing.TB, wkt string) *geos.Geom {
tb.Helper()
geom, err := geos.NewGeomFromWKT(wkt)
assert.NoError(t, err)
assert.NoError(tb, err)
return geom
}

0 comments on commit 01be1c1

Please sign in to comment.