Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions migrators/goosemigrator/goose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"io/fs"
"os"

"github.com/pressly/goose/v3"
"github.com/pressly/goose/v3/database"
Expand Down Expand Up @@ -68,7 +67,7 @@ func New(migrationsDir string, opts ...Option) *GooseMigrator {
gm := &GooseMigrator{
MigrationsDir: migrationsDir,
TableName: DefaultTableName,
FS: os.DirFS("."),
FS: nil,
}
for _, opt := range opts {
opt(gm)
Expand Down
44 changes: 41 additions & 3 deletions migrators/goosemigrator/goose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,49 @@ import (
"github.com/peterldowns/pgtestdb/migrators/goosemigrator"
)

func TestGooseMigratorFromDisk(t *testing.T) {
func TestGooseMigratorFromDiskWithSubdirectory(t *testing.T) {
t.Parallel()
ctx := context.Background()

m := goosemigrator.New("migrations")
m := goosemigrator.New("./migrations")
db := pgtestdb.New(t, pgtestdb.Config{
DriverName: "pgx",
Host: "localhost",
User: "postgres",
Password: "password",
Port: "5433",
Options: "sslmode=disable",
}, m)
assert.NotEqual(t, nil, db)

assert.NoFailures(t, func() {
var lastAppliedMigration int
err := db.QueryRowContext(ctx, "select max(version_id) from goose_db_version").Scan(&lastAppliedMigration)
assert.Nil(t, err)
check.Equal(t, 2, lastAppliedMigration)
})

var numUsers int
err := db.QueryRowContext(ctx, "select count(*) from users").Scan(&numUsers)
assert.Nil(t, err)
check.Equal(t, 0, numUsers)

var numCats int
err = db.QueryRowContext(ctx, "select count(*) from cats").Scan(&numCats)
assert.Nil(t, err)
check.Equal(t, 0, numCats)

var numBlogPosts int
err = db.QueryRowContext(ctx, "select count(*) from blog_posts").Scan(&numBlogPosts)
assert.Nil(t, err)
check.Equal(t, 0, numBlogPosts)
}

func TestGooseMigratorFromDiskWithParentDirectoryRelativePath(t *testing.T) {
t.Parallel()
ctx := context.Background()

m := goosemigrator.New("../../migrators/goosemigrator/migrations")
db := pgtestdb.New(t, pgtestdb.Config{
DriverName: "pgx",
Host: "localhost",
Expand Down Expand Up @@ -54,7 +92,7 @@ func TestGooseMigratorFromDisk(t *testing.T) {
//go:embed migrations/*.sql
var exampleFS embed.FS

func TestGooseMigratorFromFS(t *testing.T) {
func TestGooseMigratorFromEmbedFS(t *testing.T) {
t.Parallel()
ctx := context.Background()

Expand Down
Loading