-
Notifications
You must be signed in to change notification settings - Fork 529
/
provider_options_test.go
65 lines (62 loc) · 2.01 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/stretchr/testify/require"
_ "modernc.org/sqlite"
)
func TestNewProvider(t *testing.T) {
dir := t.TempDir()
db, err := sql.Open("sqlite", filepath.Join(dir, "sql_embed.db"))
require.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)
require.Error(t, err)
// Invalid dialect not allowed
_, err = goose.NewProvider("unknown-dialect", db, fsys)
require.Error(t, err)
// Nil db not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, nil, fsys)
require.Error(t, err)
// Nil store not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil, goose.WithStore(nil))
require.Error(t, err)
// Cannot set both dialect and store
store, err := database.NewStore(goose.DialectSQLite3, "custom_table")
require.NoError(t, err)
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil, goose.WithStore(store))
require.Error(t, err)
// Multiple stores not allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, nil,
goose.WithStore(store),
goose.WithStore(store),
)
require.Error(t, err)
})
t.Run("valid", func(t *testing.T) {
// Valid dialect, db, and fsys allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, fsys)
require.NoError(t, err)
// Valid dialect, db, fsys, and verbose allowed
_, err = goose.NewProvider(goose.DialectSQLite3, db, fsys,
goose.WithVerbose(testing.Verbose()),
)
require.NoError(t, err)
// Custom store allowed
store, err := database.NewStore(goose.DialectSQLite3, "custom_table")
require.NoError(t, err)
_, err = goose.NewProvider("", db, nil, goose.WithStore(store))
require.Error(t, err)
})
}