mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
More tests.
This commit is contained in:
24
conn_test.go
24
conn_test.go
@@ -1,6 +1,7 @@
|
||||
package sqlite3_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -23,6 +24,23 @@ func TestOpen_file(t *testing.T) {
|
||||
testOpen(t, filepath.Join(dir, "test.db"))
|
||||
}
|
||||
|
||||
func TestOpen_dir(t *testing.T) {
|
||||
_, err := sqlite3.Open(".")
|
||||
if err == nil {
|
||||
t.Fatal("want error")
|
||||
}
|
||||
var serr *sqlite3.Error
|
||||
if !errors.As(err, &serr) {
|
||||
t.Fatal("want sqlite3.Error")
|
||||
}
|
||||
if serr.Code != sqlite3.CANTOPEN {
|
||||
t.Fatal("want sqlite3.CANTOPEN")
|
||||
}
|
||||
if got := err.Error(); got != "sqlite3: unable to open database file" {
|
||||
t.Fatal("got message: ", got)
|
||||
}
|
||||
}
|
||||
|
||||
func testOpen(t *testing.T, name string) {
|
||||
db, err := sqlite3.Open(name)
|
||||
if err != nil {
|
||||
@@ -51,17 +69,17 @@ func testOpen(t *testing.T, name string) {
|
||||
idx := 0
|
||||
for ; stmt.Step(); idx++ {
|
||||
if ids[idx] != stmt.ColumnInt(0) {
|
||||
t.Errorf("expected %d got %d", ids[idx], stmt.ColumnInt(0))
|
||||
t.Errorf("want %d got %d", ids[idx], stmt.ColumnInt(0))
|
||||
}
|
||||
if names[idx] != stmt.ColumnText(1) {
|
||||
t.Errorf("expected %q got %q", names[idx], stmt.ColumnText(1))
|
||||
t.Errorf("want %q got %q", names[idx], stmt.ColumnText(1))
|
||||
}
|
||||
}
|
||||
if err := stmt.Err(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if idx != 3 {
|
||||
t.Errorf("expected %d rows got %d", len(ids), idx)
|
||||
t.Errorf("want %d rows got %d", len(ids), idx)
|
||||
}
|
||||
|
||||
err = stmt.Close()
|
||||
|
||||
Reference in New Issue
Block a user