Permalink
Browse files

Added test-case for issue #13 but cannot replicate the problem.

  • Loading branch information...
1 parent 9ba8570 commit e22cb5543239eb60a30d50bac966d30f2ba83be1 @feyeleanor feyeleanor committed Feb 27, 2012
Showing with 33 additions and 2 deletions.
  1. +33 −2 sqlite3_test.go
View
@@ -1,6 +1,9 @@
package sqlite3
-import "testing"
+import (
+ "os"
+ "testing"
+)
func TestSession(t *testing.T) {
Session("test.db", func(db *Database) {
@@ -12,7 +15,6 @@ func TestSession(t *testing.T) {
})
}
-
func TestTransientSession(t *testing.T) {
TransientSession(func(db *Database) {
FOO.Drop(db)
@@ -21,4 +23,33 @@ func TestTransientSession(t *testing.T) {
db.runQuery(t, "INSERT INTO foo values (?, ?)", 2, "holy moly")
db.stepThroughRows(t, FOO)
})
+}
+
+func TestOpen(t *testing.T) {
+ // Test for issue #13
+
+ // Create a new database
+ filename := "new.db"
+ os.Remove(filename)
+ db, e := Open(filename)
+ if e != nil {
+ t.Fatalf("Creating %v failed with error: %v", db, e)
+ }
+ if _, e = db.Execute( "CREATE TABLE foo (id INTEGER PRIMARY KEY ASC, name VARCHAR(10));" ); e != nil {
+ t.Fatalf("Create Table foo failed with error: %v", e)
+ }
+ db.Close()
+
+ if _, e := os.Stat(filename); e != nil {
+ t.Fatalf("Checking %v existence failed with error: %v", filename, e)
+ }
+
+ // If new.db already exists and is a valid SQLite3 database this should succeed
+ if db, e = Open(filename); e != nil {
+ t.Fatalf("Reopening %v failed with error: %v", db, e)
+ }
+ defer db.Close()
+ if _, e = db.Execute( "INSERT INTO foo (id,name) VALUES ('1', 'John');" ); e != nil {
+ t.Fatalf("Insert into foo failed with error: %v", e)
+ }
}

0 comments on commit e22cb55

Please sign in to comment.