-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecondary_index_test.go
83 lines (80 loc) · 2.04 KB
/
secondary_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
package dynmgrm
import (
"github.com/google/go-cmp/cmp"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"testing"
)
func TestSecondaryIndexExpression_Build(t *testing.T) {
type test struct {
sut secondaryIndexExpression
builder clause.Builder
exprectedTable string
exprectedTableExpr clause.Expr
expectedDist interface{}
}
tests := map[string]test{
"happy-path": {
sut: SecondaryIndex("testTable.testIndex"),
builder: &gorm.Statement{
DB: &gorm.DB{
Config: &gorm.Config{
Dialector: &mockDialector{},
},
},
},
exprectedTableExpr: clause.Expr{
SQL: `"testTable"."testIndex"`,
},
exprectedTable: "testTable.testIndex",
},
"happy-path/with-secondary-index-of": {
sut: SecondaryIndex("testIndex", SecondaryIndexOf("testTable")),
builder: &gorm.Statement{
DB: &gorm.DB{
Config: &gorm.Config{
Dialector: &mockDialector{},
},
},
},
exprectedTableExpr: clause.Expr{
SQL: `"testTable"."testIndex"`,
},
exprectedTable: "testTable.testIndex",
},
"happy-path/with-statement-table": {
sut: SecondaryIndex("testIndex"),
builder: &gorm.Statement{
Table: "testTable",
DB: &gorm.DB{
Config: &gorm.Config{
Dialector: &mockDialector{},
},
},
},
exprectedTableExpr: clause.Expr{
SQL: `"testTable"."testIndex"`,
},
exprectedTable: "testTable.testIndex",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
tt.sut.Build(tt.builder)
if statement, ok := tt.builder.(*gorm.Statement); ok {
if diff := cmp.Diff(statement.Table, tt.exprectedTable); diff != "" {
t.Errorf("Statement.Table mismatch (-want +got):\n%s", diff)
return
}
if diff := cmp.Diff(statement.TableExpr, &tt.exprectedTableExpr); diff != "" {
t.Errorf("Statement.TableExpr mismatch (-want +got):\n%s", diff)
return
}
if diff := cmp.Diff(statement.Dest, tt.expectedDist); diff != "" {
t.Errorf("Statement.Dest mismatch (-want +got):\n%s", diff)
return
}
}
})
}
}