-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_test.go
46 lines (42 loc) · 1.57 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
package spoon_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/pi9min/spoon"
)
func TestAddIndex(t *testing.T) {
tests := []struct {
name string
index *spoon.Index
expect string
}{
{
name: "Player.PlayerID, nullFiltered=false",
index: spoon.AddIndex("PlayerByPlayerID", "Player", false, spoon.KeyPart{ColumnName: "PlayerID"}),
expect: "CREATE INDEX `PlayerByPlayerID` ON `Player` (`PlayerID`)",
},
{
name: "Player.PlayerID, nullFiltered=false",
index: spoon.AddIndex("PlayerByPlayerIDEntryID", "Player", true, spoon.KeyPart{ColumnName: "PlayerID", IsOrderDesc: true}, spoon.KeyPart{ColumnName: "EntryID"}),
expect: "CREATE NULL_FILTERED INDEX `PlayerByPlayerIDEntryID` ON `Player` (`PlayerID` DESC, `EntryID`)",
},
{
name: "Player.PlayerID, nullFiltered=false",
index: spoon.AddUniqueIndex("PlayerByUniquePlayerID", "Player", false, spoon.KeyPart{ColumnName: "PlayerID"}),
expect: "CREATE UNIQUE INDEX `PlayerByUniquePlayerID` ON `Player` (`PlayerID`)",
},
{
name: "Player.PlayerID, nullFiltered=false",
index: spoon.AddUniqueIndex("PlayerByUniquePlayerIDEntryID", "Player", true, spoon.KeyPart{ColumnName: "PlayerID", IsOrderDesc: true}, spoon.KeyPart{ColumnName: "EntryID"}),
expect: "CREATE UNIQUE NULL_FILTERED INDEX `PlayerByUniquePlayerIDEntryID` ON `Player` (`PlayerID` DESC, `EntryID`)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := tt.index.CreateIndexSchema()
if diff := cmp.Diff(tt.expect, actual); diff != "" {
t.Errorf("%s", diff)
}
})
}
}