Skip to content
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: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
${{ matrix.module }}/go.sum
- run: go test -race -covermode=atomic -coverprofile=cover.out ./...
- run: go vet ./...
- run: GOOS=linux GOARCH=386 go vet ./... && GOOS=linux GOARCH=arm go vet ./...
- if: matrix.module == 'dbkit/sqlite' || matrix.module == 'gonsole/auth/sqlite' || matrix.module == 'gonsole'
run: GOOS=darwin GOARCH=arm64 go vet ./... && GOOS=windows GOARCH=amd64 go vet ./...

Expand Down Expand Up @@ -68,6 +69,7 @@ jobs:
${{ matrix.module }}/go.sum
- run: go test -race -covermode=atomic -coverprofile=cover.out ./...
- run: go vet ./...
- run: GOOS=linux GOARCH=386 go vet ./... && GOOS=linux GOARCH=arm go vet ./...

gottext:
runs-on: ubuntu-latest
Expand Down
29 changes: 22 additions & 7 deletions dbkit/postgres/open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -240,20 +241,34 @@ func openFreshHandle(t *testing.T, maxConns int) *postgres.Handle {
return mustOpen(t, openFresh(t), maxConns)
}

// openCapCase is one connection cap Open refuses and the error it returns.
type openCapCase struct {
// name names the case.
name string
// maxConns is the connection cap Open is given.
maxConns int
// want is the error Open returns.
want string
}

func TestOpenRefusesABadOption(t *testing.T) {
t.Parallel()

cases := []struct {
name string
maxConns int
want string
}{
cases := []openCapCase{
{"a missing connection cap", 0, "dbkit: the option MaxConns must be 2 or more, got 0"},
{"a connection cap of one", 1, "dbkit: the option MaxConns must be 2 or more, got 1"},
{"a negative connection cap", -1, "dbkit: the option MaxConns must be 2 or more, got -1"},
{"a connection cap past 32 bits", math.MaxInt32 + 1,
"dbkit: the option MaxConns must be 2147483647 or less, got 2147483648"},
}

if strconv.IntSize == 64 {
past32 := int64(math.MaxInt32) + 1
cases = append(cases, openCapCase{
name: "a connection cap past 32 bits",
maxConns: int(past32),
want: "dbkit: the option MaxConns must be 2147483647 or less, got 2147483648",
})
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
Expand Down
29 changes: 22 additions & 7 deletions dbkit/sqlite/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math"
"os"
"path/filepath"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -60,14 +61,20 @@ func limitOf(n int64) *int64 {
return &n
}

// optionsCase is one bad change to valid options and the error Open returns.
type optionsCase struct {
// name names the case.
name string
// change makes the one bad change to valid options.
change func(*sqlite.Options)
// want is the error Open returns.
want string
}

func TestOpenRefusesABadOption(t *testing.T) {
t.Parallel()

cases := []struct {
name string
change func(*sqlite.Options)
want string
}{
cases := []optionsCase{
{"a missing busy timeout", func(o *sqlite.Options) { o.BusyTimeout = 0 },
"dbkit: the option BusyTimeout must be 1ms or more, got 0s"},
{"a negative busy timeout", func(o *sqlite.Options) { o.BusyTimeout = -time.Millisecond },
Expand Down Expand Up @@ -98,8 +105,6 @@ func TestOpenRefusesABadOption(t *testing.T) {
"dbkit: the option CacheSize must stand above zero, got 0"},
{"a negative cache size", func(o *sqlite.Options) { o.CacheSize = -1 },
"dbkit: the option CacheSize must stand above zero, got -1"},
{"a cache size past 32 bits", func(o *sqlite.Options) { o.CacheSize = math.MaxInt32 + 1 },
"dbkit: the option CacheSize must be 2147483647 or less, got 2147483648"},
{"a missing connection cap", func(o *sqlite.Options) { o.MaxConns = 0 },
"dbkit: the option MaxConns must be 2 or more, got 0"},
{"a negative connection cap", func(o *sqlite.Options) { o.MaxConns = -2 },
Expand All @@ -119,6 +124,16 @@ func TestOpenRefusesABadOption(t *testing.T) {
{"a base folder with a question mark", func(o *sqlite.Options) { o.BaseFolder = "/srv/a?b" },
`dbkit: the option BaseFolder must hold no ?, got "/srv/a?b"`},
}

if strconv.IntSize == 64 {
past32 := int64(math.MaxInt32) + 1
cases = append(cases, optionsCase{
name: "a cache size past 32 bits",
change: func(o *sqlite.Options) { o.CacheSize = int(past32) },
want: "dbkit: the option CacheSize must be 2147483647 or less, got 2147483648",
})
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
Expand Down
Loading