-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimary_key_test.go
41 lines (37 loc) · 1.06 KB
/
primary_key_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
package spoon_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/pi9min/spoon"
)
func TestAddPrimaryKey(t *testing.T) {
tests := []struct {
name string
pk *spoon.PrimaryKey
expect string
}{
{
name: "1 single key part",
pk: spoon.AddPrimaryKey(spoon.KeyPart{ColumnName: "ID"}),
expect: "PRIMARY KEY (`ID`)",
},
{
name: "2 multiple key part",
pk: spoon.AddPrimaryKey(spoon.KeyPart{ColumnName: "ID"}, spoon.KeyPart{ColumnName: "CreatedAt", IsOrderDesc: true}),
expect: "PRIMARY KEY (`ID`, `CreatedAt` DESC)",
},
{
name: "3 multiple key part with interleave",
pk: spoon.AddPrimaryKeyWithInterleave("Balance", spoon.KeyPart{ColumnName: "CurrencyID"}, spoon.KeyPart{ColumnName: "UserID", IsOrderDesc: true}),
expect: "PRIMARY KEY (`CurrencyID`, `UserID` DESC), INTERLEAVE IN PARENT `Balance`",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := tt.pk.ToSQL()
if diff := cmp.Diff(tt.expect, actual); diff != "" {
t.Errorf("ToSQL Diff:\n%s", diff)
}
})
}
}