forked from TechBowl-japan/go-stations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_test.go
46 lines (39 loc) · 866 Bytes
/
db_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
package db_test
import (
"errors"
"os"
"testing"
"github.com/TechBowl-japan/go-stations/db"
"github.com/mattn/go-sqlite3"
)
func TestNewDB(t *testing.T) {
t.Parallel()
cases := map[string]struct {
path string
err error
}{
"Normal": {path: "../.sqlite3/db_test.db", err: nil},
"Directory not created": {path: "../.nothing/db_test.db", err: sqlite3.ErrCantOpenFullPath},
}
t.Cleanup(func() {
for _, c := range cases {
if c.err == nil {
if err := os.Remove(c.path); err != nil {
t.Error("failed to cleanup testdata, err =", err)
}
}
}
})
for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()
_, err := db.NewDB(c.path)
if err != nil {
if errors.Is(c.err, err) {
t.Errorf("unexpected value, given = %s, expected = %s\n", err, c.err)
}
}
})
}
}