Skip to content

Commit

Permalink
Test the nosqlite3 tag in CI; fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <cole.miller@canonical.com>
  • Loading branch information
cole-miller committed Mar 21, 2023
1 parent d26362d commit 6f18e4d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
golint
export GO_DQLITE_MULTITHREAD=1
go test -v -race -coverprofile=coverage.out ./...
go test -v -tags nosqlite3 ./...
VERBOSE=1 DISK=${{ matrix.disk }} ./test/dqlite-demo.sh
VERBOSE=1 DISK=${{ matrix.disk }} ./test/roles.sh
VERBOSE=1 DISK=${{ matrix.disk }} ./test/recover.sh
Expand Down
26 changes: 26 additions & 0 deletions client/store_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// +build !nosqlite3

package client_test

import (
"context"
"database/sql"
"testing"

dqlite "github.com/canonical/go-dqlite"
"github.com/canonical/go-dqlite/client"
"github.com/canonical/go-dqlite/driver"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -53,3 +58,24 @@ func TestDefaultNodeStore(t *testing.T) {
{ID: uint64(1), Address: "9.9.9.9:666"}},
servers)
}

func TestConfigMultiThread(t *testing.T) {
cleanup := dummyDBSetup(t)
defer cleanup()

err := dqlite.ConfigMultiThread()
assert.EqualError(t, err, "SQLite is already initialized")
}

func dummyDBSetup(t *testing.T) func() {
store := client.NewInmemNodeStore()
driver, err := driver.New(store)
require.NoError(t, err)
sql.Register("dummy", driver)
db, err := sql.Open("dummy", "test.db")
require.NoError(t, err)
cleanup := func() {
require.NoError(t, db.Close())
}
return cleanup
}
4 changes: 1 addition & 3 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ func newDriver(t *testing.T) (*dqlitedriver.Driver, func()) {
func newStore(t *testing.T, address string) client.NodeStore {
t.Helper()

store, err := client.DefaultNodeStore(":memory:")
require.NoError(t, err)

store := client.NewInmemNodeStore()
server := client.NodeInfo{Address: address}
require.NoError(t, store.Set(context.Background(), []client.NodeInfo{server}))

Expand Down
16 changes: 3 additions & 13 deletions driver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ func TestIntegration_QueryBindError(t *testing.T) {
assert.EqualError(t, err, "bind parameters")
}

func TestIntegration_ConfigMultiThread(t *testing.T) {
_, _, cleanup := newDB(t, 1)
defer cleanup()

err := dqlite.ConfigMultiThread()
assert.EqualError(t, err, "SQLite is already initialized")
}

func TestIntegration_LargeQuery(t *testing.T) {
db, _, cleanup := newDB(t, 3)
defer cleanup()
Expand Down Expand Up @@ -299,10 +291,9 @@ func TestIntegration_LeadershipTransfer_Tx(t *testing.T) {

func TestOptions(t *testing.T) {
// make sure applying all options doesn't break anything
store, err := client.DefaultNodeStore(":memory:")
require.NoError(t, err)
store := client.NewInmemNodeStore()
log := logging.Test(t)
_, err = driver.New(
_, err := driver.New(
store,
driver.WithLogFunc(log),
driver.WithContext(context.Background()),
Expand All @@ -329,8 +320,7 @@ func newDB(t *testing.T, n int) (*sql.DB, []*nodeHelper, func()) {
func newDBWithInfos(t *testing.T, infos []client.NodeInfo) (*sql.DB, []*nodeHelper, func()) {
helpers, helpersCleanup := newNodeHelpers(t, infos)

store, err := client.DefaultNodeStore(":memory:")
require.NoError(t, err)
store := client.NewInmemNodeStore()

require.NoError(t, store.Set(context.Background(), infos))

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down

0 comments on commit 6f18e4d

Please sign in to comment.