From 5674e19d0587e09d0649f650671cb23627d20ba8 Mon Sep 17 00:00:00 2001 From: Lars Buitinck Date: Fri, 5 Jun 2015 16:33:25 +0200 Subject: [PATCH] Test read-only databases --- sqlite3_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sqlite3_test.go b/sqlite3_test.go index f2d461b..43f7b4f 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -83,6 +83,27 @@ func TestOpen(t *testing.T) { } } +func TestReadonly(t *testing.T) { + tempFilename := TempFilename(t) + defer os.Remove(tempFilename) + + db1, err := sql.Open("sqlite3", "file:" + tempFilename) + if err != nil { + t.Fatal(err) + } + db1.Exec("CREATE TABLE test (x int, y float)") + + db2, err := sql.Open("sqlite3", "file:" + tempFilename + "?mode=ro") + if err != nil { + t.Fatal(err) + } + _ = db2 + _, err = db2.Exec("INSERT INTO test VALUES (1, 3.14)") + if err == nil { + t.Fatal("didn't expect INSERT into read-only database to work") + } +} + func TestClose(t *testing.T) { tempFilename := TempFilename(t) db, err := sql.Open("sqlite3", tempFilename)