forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_options_test.go
65 lines (62 loc) · 2.02 KB
/
provider_options_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
60
61
62
63
64
65
package goose_test
import (
"database/sql"
"path/filepath"
"testing"
"testing/fstest"
"github.com/pressly/goose/v3"
"github.com/pressly/goose/v3/database"
"github.com/pressly/goose/v3/internal/check"
_ "modernc.org/sqlite"
)
func TestNewProvider(t *testing.T) {
dir := t.TempDir()
db, err := sql.Open("sqlite", filepath.Join(dir, "sql_embed.db"))
check.NoError(t, err)
fsys := fstest.MapFS{
"1_foo.sql": {Data: []byte(migration1)},
"2_bar.sql": {Data: []byte(migration2)},
"3_baz.sql": {Data: []byte(migration3)},
"4_qux.sql": {Data: []byte(migration4)},
}
t.Run("invalid", func(t *testing.T) {
// Empty dialect not allowed
_, err = goose.NewProvider("", db, fsys)
check.HasError(t, err)
// Invalid dialect not allowed
_, err = goose.NewProvider("unknown-dialect", db, fsys)
check.HasError(t, err)
// Nil db not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, nil, fsys)
check.HasError(t, err)
// Nil store not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil, goose.WithStore(nil))
check.HasError(t, err)
// Cannot set both dialect and store
store, err := database.NewStore(goose.DialectSQLite3, "custom_table")
check.NoError(t, err)
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil, goose.WithStore(store))
check.HasError(t, err)
// Multiple stores not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil,
goose.WithStore(store),
goose.WithStore(store),
)
check.HasError(t, err)
})
t.Run("valid", func(t *testing.T) {
// Valid dialect, db, and fsys allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, fsys)
check.NoError(t, err)
// Valid dialect, db, fsys, and verbose allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, fsys,
goose.WithVerbose(testing.Verbose()),
)
check.NoError(t, err)
// Custom store allowed
store, err := database.NewStore(goose.DialectSQLite3, "custom_table")
check.NoError(t, err)
_, err = goose.NewProvider("", db, nil, goose.WithStore(store))
check.HasError(t, err)
})
}