blob: e256f9c889f9655b24dbef48d4e6ec1d7e24fc7f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package db
import "testing"
func TestOpenSQLiteFile(t *testing.T) {
// db, err := sql.Open("sqlite3", "testdata/test.db")
db, err := SetupDB("./testdata/test.db")
defer db.Close()
if err != nil {
t.Fatal("Expected to be able to set up the database.")
}
stmt := `insert into datamap(id, name) values(1,'cock')`
_, err = db.Exec(stmt)
if err != nil {
t.Errorf("Cannot add record to db")
}
rows, err := db.Query("select name from datamap")
if err != nil {
t.Errorf("Cannot run select statement")
}
defer rows.Close()
for rows.Next() {
var name string
err = rows.Scan(&name)
if err != nil {
t.Errorf("Cannot scan resulting row")
}
}
}
|