-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_anonymous_test.go
62 lines (57 loc) · 2.09 KB
/
5_anonymous_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
package test
import (
"testing"
"time"
"github.com/farseer-go/fs/trace"
"github.com/farseer-go/fs/trace/eumCallType"
"github.com/farseer-go/mapper"
"github.com/stretchr/testify/assert"
)
type TraceDetailDatabase struct {
trace.TraceDetail
DbName string // 数据库名
RowsAffected int64 // 影响行数
}
type BaseTraceDetailPO struct {
TraceId string `gorm:"not null;default:'';comment:上下文ID"`
Level int `gorm:"not null;comment:当前层级(入口为0层)"`
CallType eumCallType.Enum `gorm:"not null;comment:调用类型"`
Timeline time.Duration `gorm:"not null;default:0;comment:从入口开始统计(微秒)"`
Exception *trace.ExceptionStack `gorm:"json;not null;comment:异常信息"`
}
type TraceDetailDatabasePO struct {
BaseTraceDetailPO `gorm:"embedded"`
DbName string `gorm:"not null;default:'';comment:数据库名"`
RowsAffected int64 `gorm:"not null;default:0;comment:影响行数"`
}
// 测试匿名类型
func TestAnonymous(t *testing.T) {
po := TraceDetailDatabasePO{
BaseTraceDetailPO: BaseTraceDetailPO{
TraceId: "123456",
Level: 1,
CallType: 2,
Timeline: 3,
Exception: &trace.ExceptionStack{
ExceptionCallFile: "4",
ExceptionCallLine: 5,
ExceptionCallFuncName: "6",
ExceptionIsException: true,
ExceptionMessage: "7",
},
},
DbName: "8",
RowsAffected: 9,
}
do := mapper.Single[TraceDetailDatabase](po)
assert.Equal(t, do.Level, po.Level)
assert.Equal(t, do.CallType, po.CallType)
assert.Equal(t, do.Timeline, po.Timeline)
assert.Equal(t, do.Exception.ExceptionCallFile, po.Exception.ExceptionCallFile)
assert.Equal(t, do.Exception.ExceptionCallLine, po.Exception.ExceptionCallLine)
assert.Equal(t, do.Exception.ExceptionCallFuncName, po.Exception.ExceptionCallFuncName)
assert.Equal(t, do.Exception.ExceptionIsException, po.Exception.ExceptionIsException)
assert.Equal(t, do.Exception.ExceptionMessage, po.Exception.ExceptionMessage)
assert.Equal(t, do.DbName, po.DbName)
assert.Equal(t, do.RowsAffected, po.RowsAffected)
}