Skip to content

Commit 791a117

Browse files
committed
Revert "Remove Go 1.16 specific tests"
This reverts commit db6e9e6.
1 parent 215fa43 commit 791a117

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

migrate_go116.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//go:build go1.16
2+
// +build go1.16
3+
4+
package migrate
5+
6+
import (
7+
"embed"
8+
"net/http"
9+
)
10+
11+
// A set of migrations loaded from an go1.16 embed.FS
12+
13+
type EmbedFileSystemMigrationSource struct {
14+
FileSystem embed.FS
15+
16+
Root string
17+
}
18+
19+
var _ MigrationSource = (*EmbedFileSystemMigrationSource)(nil)
20+
21+
func (f EmbedFileSystemMigrationSource) FindMigrations() ([]*Migration, error) {
22+
return findMigrations(http.FS(f.FileSystem), f.Root)
23+
}

migrate_go116_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//go:build go1.16
2+
// +build go1.16
3+
4+
package migrate
5+
6+
import (
7+
"embed"
8+
9+
. "gopkg.in/check.v1"
10+
)
11+
12+
//go:embed test-migrations/*
13+
var testEmbedFS embed.FS
14+
15+
func (s *SqliteMigrateSuite) TestEmbedSource(c *C) {
16+
migrations := EmbedFileSystemMigrationSource{
17+
FileSystem: testEmbedFS,
18+
Root: "test-migrations",
19+
}
20+
21+
// Executes two migrations
22+
n, err := Exec(s.Db, "sqlite3", migrations, Up)
23+
c.Assert(err, IsNil)
24+
c.Assert(n, Equals, 2)
25+
26+
// Has data
27+
id, err := s.DbMap.SelectInt("SELECT id FROM people")
28+
c.Assert(err, IsNil)
29+
c.Assert(id, Equals, int64(1))
30+
}

0 commit comments

Comments
 (0)