-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtable_test.go
53 lines (47 loc) · 1.4 KB
/
table_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
package core
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadTable(t *testing.T) {
tcs := NewTableCacheStruct()
table, err := LoadTable(tcs, "./testdata", nil, "cities", nil)
assert.Nil(t, err)
if assert.NotNil(t, table) {
assert.NotNil(t, table.BasicTable)
assert.Equal(t, 15, len(table.Attributes))
regionList, err2 := table.GetAttribute("region_list")
assert.Nil(t, err2)
if assert.NotNil(t, regionList) {
assert.NotNil(t, regionList.MapperConfig)
assert.Equal(t, regionList.MapperConfig["delim"], ",")
assert.Equal(t, MapperTypeFromString(regionList.MappingStrategy), StringEnum)
assert.NotNil(t, regionList.mapperInstance)
}
name, err3 := table.GetAttribute("name")
assert.Nil(t, err3)
if assert.NotNil(t, name) {
assert.True(t, name.IsBSI())
}
}
}
func TestLoadTableWithPK(t *testing.T) {
tcs := NewTableCacheStruct()
table, err := LoadTable(tcs, "./testdata", nil, "cityzip", nil)
assert.Nil(t, err)
pki, err2 := table.GetPrimaryKeyInfo()
assert.Nil(t, err2)
assert.NotNil(t, pki)
assert.Equal(t, len(pki), 2)
}
func TestLoadTableWithRelation(t *testing.T) {
tcs := NewTableCacheStruct()
table, err := LoadTable(tcs, "./testdata", nil, "cityzip", nil)
assert.Nil(t, err)
fka, err2 := table.GetAttribute("city_id")
assert.Nil(t, err2)
tab, spec, err3 := fka.GetFKSpec()
assert.Nil(t, err3)
assert.NotNil(t, tab)
assert.NotNil(t, spec)
}