Skip to content

Commit

Permalink
Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jul 10, 2024
1 parent 88b5b40 commit f537ab9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
4 changes: 4 additions & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (c *conn) Raw() *sqlite3.Conn {

// Deprecated: use BeginTx instead.
func (c *conn) Begin() (driver.Tx, error) {
// notest
return c.BeginTx(context.Background(), driver.TxOptions{})
}

Expand Down Expand Up @@ -287,6 +288,7 @@ func (c *conn) Rollback() error {
}

func (c *conn) Prepare(query string) (driver.Stmt, error) {
// notest
return c.PrepareContext(context.Background(), query)
}

Expand Down Expand Up @@ -363,11 +365,13 @@ func (s *stmt) NumInput() int {

// Deprecated: use ExecContext instead.
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
// notest
return s.ExecContext(context.Background(), namedValues(args))
}

// Deprecated: use QueryContext instead.
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
// notest
return s.QueryContext(context.Background(), namedValues(args))
}

Expand Down
1 change: 1 addition & 0 deletions ext/bloom/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func (c *cursor) EOF() bool {
}

func (c *cursor) RowID() (int64, error) {
// notest // WITHOUT ROWID
return 0, nil
}

Expand Down
5 changes: 5 additions & 0 deletions ext/pivot/pivot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func TestRegister(t *testing.T) {
t.Errorf("got %d, want 3", got)
}
}

err = db.Exec(`ALTER TABLE v_x RENAME TO v_y`)
if err != nil {
t.Fatal(err)
}
}

func TestRegister_errors(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions ext/zorder/zorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func Register(db *sqlite3.Conn) error {

func zorder(ctx sqlite3.Context, arg ...sqlite3.Value) {
var x [63]int64
for i := range arg {
x[i] = arg[i].Int64()
}
if len(arg) > len(x) {
ctx.ResultError(util.ErrorString("zorder: too many parameters"))
return
}
for i := range arg {
x[i] = arg[i].Int64()
}

var z int64
if len(arg) > 0 {
for i := 0; i < 63; i++ {
for i := range x {
j := i % len(arg)
z |= (x[j] & 1) << i
x[j] >>= 1
Expand Down
14 changes: 14 additions & 0 deletions ext/zorder/zorder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package zorder_test

import (
"strconv"
"strings"
"testing"

"github.com/ncruces/go-sqlite3/driver"
Expand Down Expand Up @@ -94,4 +96,16 @@ func TestRegister_error(t *testing.T) {
if err == nil {
t.Error("want error")
}

var buf strings.Builder
buf.WriteString("SELECT zorder(0")
for i := 1; i < 80; i++ {
buf.WriteByte(',')
buf.WriteString(strconv.Itoa(0))
}
buf.WriteByte(')')
err = db.QueryRow(buf.String()).Scan(&got)
if err == nil {
t.Error("want error")
}
}
19 changes: 18 additions & 1 deletion tests/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func TestConn_SetInterrupt(t *testing.T) {
if err != nil {
t.Fatal(err)
}

db.SetInterrupt(ctx)
if got := db.GetInterrupt(); got != ctx {
t.Errorf("got %v, want %v", got, ctx)
}
}

func TestConn_Prepare_empty(t *testing.T) {
Expand Down Expand Up @@ -372,13 +377,25 @@ func TestConn_SetAuthorizer(t *testing.T) {
defer db.Close()

err = db.SetAuthorizer(func(action sqlite3.AuthorizerActionCode, name3rd, name4th, schema, nameInner string) sqlite3.AuthorizerReturnCode {
if action != sqlite3.AUTH_PRAGMA {
t.Errorf("got %v, want PRAGMA", action)
}
if name3rd != "busy_timeout" {
t.Errorf("got %q, want busy_timeout", name3rd)
}
if name4th != "5000" {
t.Errorf("got %q, want 5000", name4th)
}
if schema != "main" {
t.Errorf("got %q, want main", schema)
}
return sqlite3.AUTH_DENY
})
if err != nil {
t.Fatal(err)
}

err = db.Exec(`SELECT * FROM sqlite_schema`)
err = db.Exec(`PRAGMA main.busy_timeout=5000`)
if !errors.Is(err, sqlite3.AUTH) {
t.Errorf("got %v, want sqlite3.AUTH", err)
}
Expand Down

0 comments on commit f537ab9

Please sign in to comment.