forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joins_test.go
52 lines (46 loc) · 1.03 KB
/
joins_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
package gorm
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
type JoinsModel struct {
Id string
ParentName string
Child JoinsChild `gorm:"association_foreignkey:Id;foreignkey:ModelId"`
Parent JoinsParent `gorm:"association_foreignkey:Name;foreignkey:ParentName"`
}
type JoinsChild struct {
ModelId string
}
type JoinsParent struct {
Name string
}
func TestJoinInfo(t *testing.T) {
tests := []struct {
assoc string
tableName string
sourceKeys []string
targetKeys []string
}{
{
"Child",
"joins_children",
[]string{"joins_models.id"},
[]string{"child.model_id"},
},
{
"Parent",
"joins_parents",
[]string{"joins_models.parent_name"},
[]string{"parent.name"},
},
}
for _, test := range tests {
tableName, sourceKeys, targetKeys, err := JoinInfo(context.Background(), &JoinsModel{}, test.assoc)
assert.Equal(t, test.tableName, tableName)
assert.Equal(t, test.sourceKeys, sourceKeys)
assert.Equal(t, test.targetKeys, targetKeys)
assert.Nil(t, err)
}
}