fix: default migration authoring directory to cwd

This commit is contained in:
end committed 2026-10-28 15:39:47 -07:00
1 parent 501629f225
commit b49a6ae449
2 files changed
+31 -6

No files matched your search

+28 -3
View File
@@ -41,11 +41,36 @@ func TestGeneratedConsumerAndArtifactBoundary(t *testing.T) {
if runtime.GOOS == "windows" {
osName = "linux"
}
for _, tc := range []struct{ name, kind string }{{"initial", "sql"}, {"test", "go"}, {"create_test", "go"}, {osName, "go"}} {
execute(dir, tool, "create", "--dir", migrations, tc.name, tc.kind)
execute(dir, tool, "fix", "--dir", migrations)
for i, tc := range []struct{ name, kind string }{{"initial", "sql"}, {"test", "go"}, {"create_test", "go"}, {osName, "go"}} {
if i%2 == 0 {
execute(migrations, tool, "create", tc.name, tc.kind)
execute(migrations, tool, "fix")
} else {
execute(dir, tool, "create", "--dir", migrations, tc.name, tc.kind)
execute(dir, tool, "fix", "--dir", migrations)
}
}
execute(dir, tool, "fix", "--dir", migrations)
entries, err := os.ReadDir(migrations)
if err != nil {
t.Fatal(err)
}
wantFiles := []string{"00001_initial.sql", "00002_test_migration.go", "00003_create_test_migration.go", "00004_" + osName + "_migration.go", "register.go"}
if len(entries) != len(wantFiles) {
t.Fatalf("migration files: %v", entries)
}
for i, entry := range entries {
if entry.Name() != wantFiles[i] {
t.Fatalf("migration file: got %s, want %s", entry.Name(), wantFiles[i])
}
}
entries, err = os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
if len(entries) != 2 || entries[0].Name() != "corestack-goose" || entries[1].Name() != "migrations" {
t.Fatalf("unexpected writes outside migration directory: %v", entries)
}
source, err := os.ReadFile("testdata/consumer/main.go")
if err != nil {
t.Fatal(err)