forked from uptrace/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqliteshim_test.go
59 lines (52 loc) · 1.17 KB
/
sqliteshim_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
59
package sqliteshim_test
import (
"database/sql"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uptrace/bun/driver/sqliteshim"
)
func TestShim(t *testing.T) {
sqldb, err := sqlOpen(t, sqliteshim.ShimName)
require.NoError(t, err)
_, err = sqldb.Exec("SELECT 1")
if !sqliteshim.HasDriver() {
assert.ErrorAs(t, err, new(*sqliteshim.UnsupportedError))
return
}
assert.NoError(t, err)
}
func TestDriver(t *testing.T) {
if !sqliteshim.HasDriver() {
t.SkipNow()
}
sqldb, err := sqlOpen(t, sqliteshim.DriverName())
require.NoError(t, err)
_, err = sqldb.Exec("SELECT 1")
require.NoError(t, err)
}
func TestNoImports(t *testing.T) {
if sqliteshim.HasDriver() {
t.SkipNow()
}
drivers := []string{
"sqlite", // modernc
"sqlite3", // mattn
}
for _, driverName := range drivers {
t.Run(driverName, func(t *testing.T) {
_, err := sqlOpen(t, driverName)
require.Error(t, err)
})
}
}
func sqlOpen(t *testing.T, driverName string) (*sql.DB, error) {
sqldb, err := sql.Open(driverName, ":memory:")
if err != nil {
return sqldb, err
}
t.Cleanup(func() {
assert.NoError(t, sqldb.Close())
})
return sqldb, nil
}