go-sqlite3/error_test.go

38 lines
650 B
Go
Raw Normal View History

package sqlite3
import (
"database/sql"
"io/ioutil"
"os"
"path"
"testing"
)
func TestFailures(t *testing.T) {
dirName, err := ioutil.TempDir("", "sqlite3")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dirName)
dbFileName := path.Join(dirName, "test.db")
f, err := os.Create(dbFileName)
if err != nil {
t.Error(err)
}
f.Write([]byte{1, 2, 3, 4, 5})
f.Close()
db, err := sql.Open("sqlite3", dbFileName)
if err == nil {
_, err = db.Exec("drop table foo")
}
if err != ErrNotADB {
t.Error("wrong error code for corrupted DB")
}
2013-09-03 14:36:33 +04:00
if err.Error() == "" {
t.Error("wrong error string for corrupted DB")
}
db.Close()
}