-
Notifications
You must be signed in to change notification settings - Fork 5
/
embed_go116_test.go
51 lines (43 loc) · 1.3 KB
/
embed_go116_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
//go:build go1.16
// +build go1.16
package schema
import (
"embed"
"io/fs"
"testing"
"testing/fstest"
)
//go:embed test-migrations
var exampleMigrations embed.FS
func TestMigrationsFromEmbedFS(t *testing.T) {
migrations, err := FSMigrations(exampleMigrations, "test-migrations/saas/*.sql")
if err != nil {
t.Error(err)
}
expectedCount := 2
if len(migrations) != expectedCount {
t.Errorf("Expected %d migrations, got %d", expectedCount, len(migrations))
}
SortMigrations(migrations)
expectID(t, migrations[0], "2019-01-01 0900 Create Users")
expectScriptMatch(t, migrations[0], `^CREATE TABLE users`)
expectID(t, migrations[1], "2019-01-03 1000 Create Affiliates")
expectScriptMatch(t, migrations[1], `^CREATE TABLE affiliates`)
}
func TestMigrationsWithInvalidGlob(t *testing.T) {
_, err := FSMigrations(exampleMigrations, "/a/path[]with/bad/glob/pattern")
expectErrorContains(t, err, "/a/path[]with/bad/glob/pattern")
}
func TestFSMigrationsWithInvalidFiles(t *testing.T) {
testfs := fstest.MapFS{
"invalid-migrations": &fstest.MapFile{
Mode: fs.ModeDir,
},
"invalid-migrations/real.sql": &fstest.MapFile{
Data: []byte("File contents"),
},
"invalid-migrations/fake.sql": nil,
}
_, err := FSMigrations(testfs, "invalid-migrations/*.sql")
expectErrorContains(t, err, "fake.sql")
}