Files
goclaw/cmd/migrate_test.go
T
thotam cab639d15e fix(migrate): use iofs source so migrations load on Windows (#1358)
`goclaw migrate up` (and every other migrate subcommand) failed on Windows
with `create migrator: failed to open source, "file:///D:/.../migrations":
open .: The filename, directory name, or volume label syntax is incorrect.`

golang-migrate's file source driver mis-parses absolute drive-letter file://
URLs; the drive-letter formatting in absoluteToFileURI produced a URL the
driver could not open. Replace the file:// URL with an iofs source over
os.DirFS, which uses native OS path handling and works identically on every
platform. Drop the now-unused absoluteToFileURI/migrationsSourceURL helpers
and their URL-shape tests, and add a DB-free regression test that opens the
real migrations directory via newMigrationSource().

Verified end-to-end on Windows: `migrate version` and `migrate up` now run.
2026-07-05 12:26:42 +07:00

30 lines
806 B
Go

package cmd
import (
"path/filepath"
"testing"
)
// TestNewMigrationSource_LoadsMigrations guards against the Windows regression
// where golang-migrate's file:// source driver failed to open an absolute
// drive-letter path (e.g. "file:///D:/..." → "open ." error). The iofs source
// over os.DirFS must load the real migrations directory on every platform.
func TestNewMigrationSource_LoadsMigrations(t *testing.T) {
migrationsDir = filepath.Join("..", "migrations")
t.Cleanup(func() { migrationsDir = "" })
src, err := newMigrationSource()
if err != nil {
t.Fatalf("newMigrationSource: %v", err)
}
defer src.Close()
first, err := src.First()
if err != nil {
t.Fatalf("read first migration: %v", err)
}
if first != 1 {
t.Errorf("first migration version = %d, want 1", first)
}
}