-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
index_test.go
89 lines (77 loc) · 1.69 KB
/
index_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package rel
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateIndex(t *testing.T) {
var (
options = []IndexOption{
Options("options"),
Optional(true),
}
index = createIndex("table", "add_idx", []string{"add"}, options)
)
assert.Equal(t, Index{
Table: "table",
Name: "add_idx",
Columns: []string{"add"},
Optional: true,
Options: "options",
}, index)
}
func TestCreateUniqueIndex(t *testing.T) {
var (
options = []IndexOption{
Options("options"),
}
index = createUniqueIndex("table", "add_idx", []string{"add"}, options)
)
assert.Equal(t, Index{
Table: "table",
Name: "add_idx",
Unique: true,
Columns: []string{"add"},
Options: "options",
}, index)
}
func TestCreateFilteredUniqueIndex(t *testing.T) {
var (
options = []IndexOption{
Options("options"),
Eq("deleted", false),
}
index = createUniqueIndex("table", "add_idx", []string{"add"}, options)
)
assert.Equal(t, Index{
Table: "table",
Name: "add_idx",
Unique: true,
Columns: []string{"add"},
Filter: FilterQuery{
Type: FilterEqOp,
Field: "deleted",
Value: false,
},
Options: "options",
}, index)
}
func TestDropIndex(t *testing.T) {
var (
options = []IndexOption{
Options("options"),
}
index = dropIndex("table", "drop", options)
)
assert.Equal(t, Index{
Op: SchemaDrop,
Table: "table",
Name: "drop",
Options: "options",
}, index)
}
func TestIndex_Description(t *testing.T) {
assert.Equal(t, "create index idx_test on tests", Index{Name: "idx_test", Table: "tests"}.description())
}
func TestIndex_InternalMigration(t *testing.T) {
assert.NotPanics(t, func() { Index{}.internalMigration() })
}