mirror of https://github.com/pressly/goose.git
Fixes the tests
parent
42766096ee
commit
8a6c2299f0
|
@ -109,6 +109,12 @@ func collectMigrations(dirpath string, current, target int64) (Migrations, error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
migrations = sortAndConnectMigrations(migrations)
|
||||||
|
|
||||||
|
return migrations, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortAndConnectMigrations(migrations Migrations) Migrations {
|
||||||
sort.Sort(migrations)
|
sort.Sort(migrations)
|
||||||
|
|
||||||
// now that we're sorted in the appropriate direction,
|
// now that we're sorted in the appropriate direction,
|
||||||
|
@ -122,7 +128,7 @@ func collectMigrations(dirpath string, current, target int64) (Migrations, error
|
||||||
migrations[i].Previous = prev
|
migrations[i].Previous = prev
|
||||||
}
|
}
|
||||||
|
|
||||||
return migrations, nil
|
return migrations
|
||||||
}
|
}
|
||||||
|
|
||||||
func versionFilter(v, current, target int64) bool {
|
func versionFilter(v, current, target int64) bool {
|
||||||
|
|
|
@ -8,7 +8,7 @@ func newMigration(v int64, src string) *Migration {
|
||||||
return &Migration{Version: v, Previous: -1, Next: -1, Source: src}
|
return &Migration{Version: v, Previous: -1, Next: -1, Source: src}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrationMapSortUp(t *testing.T) {
|
func TestMigrationSort(t *testing.T) {
|
||||||
|
|
||||||
ms := Migrations{}
|
ms := Migrations{}
|
||||||
|
|
||||||
|
@ -18,30 +18,13 @@ func TestMigrationMapSortUp(t *testing.T) {
|
||||||
ms = append(ms, newMigration(20129000, "test"))
|
ms = append(ms, newMigration(20129000, "test"))
|
||||||
ms = append(ms, newMigration(20127000, "test"))
|
ms = append(ms, newMigration(20127000, "test"))
|
||||||
|
|
||||||
ms.Sort(true) // sort Upwards
|
ms = sortAndConnectMigrations(ms)
|
||||||
|
|
||||||
sorted := []int64{20120000, 20127000, 20128000, 20129000}
|
sorted := []int64{20120000, 20127000, 20128000, 20129000}
|
||||||
|
|
||||||
validateMigrationSort(t, ms, sorted)
|
validateMigrationSort(t, ms, sorted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrationMapSortDown(t *testing.T) {
|
|
||||||
|
|
||||||
ms := Migrations{}
|
|
||||||
|
|
||||||
// insert in any order
|
|
||||||
ms = append(ms, newMigration(20120000, "test"))
|
|
||||||
ms = append(ms, newMigration(20128000, "test"))
|
|
||||||
ms = append(ms, newMigration(20129000, "test"))
|
|
||||||
ms = append(ms, newMigration(20127000, "test"))
|
|
||||||
|
|
||||||
ms.Sort(false) // sort Downwards
|
|
||||||
|
|
||||||
sorted := []int64{20129000, 20128000, 20127000, 20120000}
|
|
||||||
|
|
||||||
validateMigrationSort(t, ms, sorted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
|
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
|
||||||
|
|
||||||
for i, m := range ms {
|
for i, m := range ms {
|
||||||
|
|
Loading…
Reference in New Issue