-
Notifications
You must be signed in to change notification settings - Fork 1
/
deepcopy_fix_test.go
61 lines (51 loc) · 2.14 KB
/
deepcopy_fix_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
package deepcopy
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// src
type TopicItemSrc struct {
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"`
CreateTime string `protobuf:"bytes,3,opt,name=CreateTime,proto3" json:"CreateTime,omitempty"`
}
// src
type AllTopicResp struct {
TopicItem []*TopicItemSrc `protobuf:"bytes,1,rep,name=TopicItem,proto3" json:"TopicItem,omitempty"`
Total int32 `protobuf:"varint,2,opt,name=Total,proto3" json:"Total,omitempty"` //总条数
}
// desc
type AllTopicResp_AllTopicRespData struct {
TopicItem []*TopicItemDst `protobuf:"bytes,1,rep,name=TopicItem,proto3" json:"TopicItem,omitempty"`
Total int32 `protobuf:"varint,2,opt,name=Total,proto3" json:"Total,omitempty"` //总条数
}
type TopicItemDst struct {
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"`
CreateTime string `protobuf:"bytes,3,opt,name=CreateTime,proto3" json:"CreateTime,omitempty"`
}
type AllTopicResp2 struct {
Code int32 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"`
Data *AllTopicResp_AllTopicRespData `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
}
func TestCopy(t *testing.T) {
resp := AllTopicResp{Total: 100, TopicItem: []*TopicItemSrc{
{ID: "111", Name: "111"},
{ID: "111", Name: "222"},
}}
rsp := AllTopicResp2{Data: &AllTopicResp_AllTopicRespData{}}
Copy(rsp.Data, resp).Do()
fmt.Printf("%#v\n", resp)
fmt.Printf("%#v\n", rsp.Data)
assert.NotNil(t, rsp.Data)
assert.Equal(t, rsp.Data.Total, resp.Total)
assert.Equal(t, len(rsp.Data.TopicItem), len(resp.TopicItem))
assert.Greater(t, len(rsp.Data.TopicItem), 0)
assert.Greater(t, len(resp.TopicItem), 0)
for i, v := range resp.TopicItem {
assert.Equal(t, v.ID, rsp.Data.TopicItem[i].ID)
assert.Equal(t, v.Name, rsp.Data.TopicItem[i].Name)
}
}