aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_test.go
diff options
context:
space:
mode:
authorSerge Hallyn <serge.hallyn@ubuntu.com>2015-04-10 11:32:18 -0500
committerSerge Hallyn <serge.hallyn@ubuntu.com>2015-04-13 11:48:01 -0500
commitf91a09fb506e7543841b4a9725e16da84fc82b72 (patch)
treeb61206bd0f83f9cb198dbc4ccf6c3faf2934c9da /sqlite3_test.go
parentMerge pull request #188 from larsmans/optimize (diff)
downloadgolite-f91a09fb506e7543841b4a9725e16da84fc82b72.tar.gz
golite-f91a09fb506e7543841b4a9725e16da84fc82b72.tar.xz
Add a txlock option when opening databases (v2)
When specified, changes the default locking at a tx.Begin. Changelog (v2): Add a testcase to ensure _txlock is properly handled. Closes #189 Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Diffstat (limited to '')
-rw-r--r--sqlite3_test.go44
1 files changed, 39 insertions, 5 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go
index aa86011..deb9706 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -9,6 +9,7 @@ import (
"crypto/rand"
"database/sql"
"encoding/hex"
+ "fmt"
"net/url"
"os"
"path/filepath"
@@ -25,11 +26,17 @@ func TempFilename() string {
return filepath.Join(os.TempDir(), "foo"+hex.EncodeToString(randBytes)+".db")
}
-func TestOpen(t *testing.T) {
+func doTestOpen(t *testing.T, option string) (string, error) {
+ var url string
tempFilename := TempFilename()
- db, err := sql.Open("sqlite3", tempFilename)
+ if option != "" {
+ url = tempFilename + option
+ } else {
+ url = tempFilename
+ }
+ db, err := sql.Open("sqlite3", url)
if err != nil {
- t.Fatal("Failed to open database:", err)
+ return "Failed to open database:", err
}
defer os.Remove(tempFilename)
defer db.Close()
@@ -37,11 +44,38 @@ func TestOpen(t *testing.T) {
_, err = db.Exec("drop table foo")
_, err = db.Exec("create table foo (id integer)")
if err != nil {
- t.Fatal("Failed to create table:", err)
+ return "Failed to create table:", err
}
if stat, err := os.Stat(tempFilename); err != nil || stat.IsDir() {
- t.Error("Failed to create ./foo.db")
+ return "Failed to create ./foo.db", nil
+ }
+
+ return "", nil
+}
+
+func TestOpen(t *testing.T) {
+ cases := map[string]bool{
+ "": true,
+ "?_txlock=immediate": true,
+ "?_txlock=deferred": true,
+ "?_txlock=exclusive": true,
+ "?_txlock=bogus": false,
+ }
+ for option, expectedPass := range cases {
+ result, err := doTestOpen(t, option)
+ if result == "" {
+ if ! expectedPass {
+ errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
+ t.Fatal(errmsg)
+ }
+ } else if expectedPass {
+ if err == nil {
+ t.Fatal(result)
+ } else {
+ t.Fatal(result, err)
+ }
+ }
}
}