-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathmigration_info_test.go
70 lines (62 loc) · 1.11 KB
/
migration_info_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package popx
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
var migrations = Migrations{
{
Version: "1",
DBType: "all",
},
{
Version: "1",
DBType: "postgres",
},
{
Version: "2",
DBType: "cockroach",
},
{
Version: "2",
DBType: "all",
},
{
Version: "3",
DBType: "all",
},
{
Version: "3",
DBType: "mysql",
},
}
func TestFilterMigrations(t *testing.T) {
t.Run("db=mysql", func(t *testing.T) {
assert.Equal(t, Migrations{
migrations[0],
migrations[3],
migrations[5],
}, migrations.SortAndFilter("mysql"))
assert.Equal(t, Migrations{
migrations[5],
migrations[3],
migrations[0],
}, migrations.SortAndFilter("mysql", sort.Reverse))
})
}
func TestSortingMigrations(t *testing.T) {
t.Run("case=enforces precedence for specific migrations", func(t *testing.T) {
expectedOrder := Migrations{
migrations[1],
migrations[0],
migrations[2],
migrations[3],
migrations[5],
migrations[4],
}
sort.Sort(migrations)
assert.Equal(t, expectedOrder, migrations)
})
}