aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Knight <robertknight@gmail.com>2013-11-19 14:05:48 +0000
committerRobert Knight <robertknight@gmail.com>2013-11-19 14:05:48 +0000
commit72bb737cf97755013eafb2a2ab56d09cdeee3e8b (patch)
tree5f51a2061c0fdfe167e7056aabb9e399f45527a9
parentUpdate test expectations follow change of concrete error type (diff)
downloadgolite-72bb737cf97755013eafb2a2ab56d09cdeee3e8b.tar.gz
golite-72bb737cf97755013eafb2a2ab56d09cdeee3e8b.tar.xz
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
-rw-r--r--error_test.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/error_test.go b/error_test.go
index 0f92881..bf7bb3c 100644
--- a/error_test.go
+++ b/error_test.go
@@ -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)
+ }
+}