-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
sqlite_pure_test.go
58 lines (50 loc) · 1.34 KB
/
sqlite_pure_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build !cgo || (cgo && pure)
// +build !cgo cgo,pure
package sqlite
import (
"database/sql"
"database/sql/driver"
"os"
"testing"
"modernc.org/sqlite"
)
const (
// This is the DSN of the in-memory SQLite database for these tests.
InMemoryDSN = "testdatabase"
// This is the custom SQLite driver name.
CustomDriverName = "my_custom_driver"
)
func TestMain(m *testing.M) {
// Register a custom function to the default SQLite driver.
sqlite.MustRegisterDeterministicScalarFunction("my_custom_function", -1, func(ctx *sqlite.FunctionContext, args []driver.Value) (driver.Value, error) {
return "my-result", nil
})
// Register the custom SQlite driver.
// modernc.org/sqlite doesn't support registering functions to custom drivers.
sql.Register(CustomDriverName,
&sqlite.Driver{},
)
rows = append(rows, []testRow{
{
description: "Explicit default driver, custom function",
dialector: &Dialector{
DriverName: DriverName,
DSN: InMemoryDSN,
},
openSuccess: true,
query: "SELECT my_custom_function()",
querySuccess: true,
},
{
description: "Custom driver, custom function",
dialector: &Dialector{
DriverName: CustomDriverName,
DSN: InMemoryDSN,
},
openSuccess: true,
query: "SELECT my_custom_function()",
querySuccess: false,
},
}...)
os.Exit(m.Run())
}