Add unit test for enhanced error reporting
Add a test to check for a useful response for a SQL query that cannot be executed due to a constraint failure
This commit is contained in:
parent
e0729751ac
commit
72bb737cf9
|
@ -8,7 +8,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestFailures(t *testing.T) {
|
||||
func TestCorruptDbErrors(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -37,3 +37,28 @@ func TestFailures(t *testing.T) {
|
|||
}
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func TestSqlLogicErrors(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("CREATE TABLE Foo (id INT PRIMARY KEY)")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
const expectedErr = "table Foo already exists"
|
||||
_, err = db.Exec("CREATE TABLE Foo (id INT PRIMARY KEY)")
|
||||
if err.Error() != expectedErr {
|
||||
t.Errorf("Unexpected error: %s, expected %s", err.Error(), expectedErr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue