diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 705a1c8..c579fbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 ./... @@ -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 diff --git a/dbkit/postgres/open_test.go b/dbkit/postgres/open_test.go index dcd43e4..ef510c7 100644 --- a/dbkit/postgres/open_test.go +++ b/dbkit/postgres/open_test.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "testing" "time" @@ -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() diff --git a/dbkit/sqlite/options_test.go b/dbkit/sqlite/options_test.go index 47cd6f7..c0f5f1e 100644 --- a/dbkit/sqlite/options_test.go +++ b/dbkit/sqlite/options_test.go @@ -7,6 +7,7 @@ import ( "math" "os" "path/filepath" + "strconv" "testing" "time" @@ -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 }, @@ -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 }, @@ -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()