-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_cgo_test.go
More file actions
45 lines (35 loc) · 846 Bytes
/
sqlite_cgo_test.go
File metadata and controls
45 lines (35 loc) · 846 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build cgo
// +build cgo
package sqlite
import (
"sync"
"testing"
"github.com/agentio/sqlite/cgosqlite"
"github.com/agentio/sqlite/sqliteh"
)
// ensure LogCallback is convertible to cgosqlite.LogCallback
var _ cgosqlite.LogCallback = cgosqlite.LogCallback(LogCallback(func(code sqliteh.Code, msg string) {}))
func TestSetLogCallback(t *testing.T) {
var mu sync.Mutex
var logs []string
err := SetLogCallback(func(code sqliteh.Code, msg string) {
mu.Lock()
defer mu.Unlock()
logs = append(logs, msg)
})
if err != nil {
t.Fatal(err)
}
defer SetLogCallback(nil)
db := openTestDB(t)
_, err = db.Exec("SELECT * FROM nonexistent_table")
if err == nil {
t.Fatal("expected error from invalid SQL")
}
mu.Lock()
gotLogs := len(logs) > 0
mu.Unlock()
if !gotLogs {
t.Fatal("expected to receive log messages")
}
}