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) + } +}