Skip to content

Commit 79df247

Browse files
committed
Blob I/O: move test data / connection
1 parent 606d2d2 commit 79df247

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

blob_io_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ import (
1616
"testing"
1717
)
1818

19-
func TestBlobIO(t *testing.T) {
20-
db, err := sql.Open("sqlite3", "file:testblobio?mode=memory&cache=shared")
19+
func blobTestData(dbname string, rowid int64, blob []byte) (*sql.DB, *SQLiteConn, error) {
20+
db, err := sql.Open("sqlite3", "file:"+dbname+"?mode=memory&cache=shared")
2121
if err != nil {
22-
t.Fatal("Fail to open:", err)
22+
return nil, nil, err
2323
}
24-
defer db.Close()
2524

2625
conn, err := db.Conn(context.Background())
2726
if err != nil {
28-
t.Fatal("Failed to get raw connection:", err)
27+
return nil, nil, err
2928
}
3029
defer conn.Close()
3130

@@ -35,13 +34,8 @@ func TestBlobIO(t *testing.T) {
3534
return nil
3635
})
3736
if err != nil {
38-
t.Fatal("Failed to get raw connection:", err)
37+
return nil, nil, err
3938
}
40-
defer driverConn.Close()
41-
42-
// Test data
43-
expected := []byte("I ❤️ SQLite in \x00\x01\x02…")
44-
rowid := int64(6581)
4539

4640
query := `
4741
CREATE TABLE data (
@@ -52,10 +46,24 @@ func TestBlobIO(t *testing.T) {
5246
VALUES (:rowid, :value);
5347
`
5448

55-
_, err = db.Exec(query, sql.Named("rowid", rowid), sql.Named("value", expected))
49+
_, err = db.Exec(query, sql.Named("rowid", rowid), sql.Named("value", blob))
50+
if err != nil {
51+
return nil, nil, err
52+
}
53+
54+
return db, driverConn, nil
55+
}
56+
57+
func TestBlobIO(t *testing.T) {
58+
rowid := int64(6581)
59+
expected := []byte("I ❤️ SQLite in \x00\x01\x02…")
60+
61+
db, driverConn, err := blobTestData("testblobio", rowid, expected)
5662
if err != nil {
57-
t.Fatal("Failed to execute", err)
63+
t.Fatal("Failed to get raw connection:", err)
5864
}
65+
defer driverConn.Close()
66+
defer db.Close()
5967

6068
// Open blob
6169
blob, err := driverConn.Blob("main", "data", "value", rowid, 0)

0 commit comments

Comments
 (0)