Test read-only databases

type
Lars Buitinck 2015-06-05 16:33:25 +02:00
parent a3efcea001
commit 5674e19d05
1 changed files with 21 additions and 0 deletions

View File

@ -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)