|
| 1 | +package deepcopy |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +type DiaryResourceTypeDst int32 |
| 10 | + |
| 11 | +const ( |
| 12 | + // 文本 |
| 13 | + DiaryResourceType_DiaryResourceTypeTextDst DiaryResourceTypeDst = 0 |
| 14 | + // 图片 |
| 15 | + DiaryResourceType_DiaryResourceTypeImageDst DiaryResourceTypeDst = 1 |
| 16 | + // 视频 |
| 17 | + DiaryResourceType_DiaryResourceTypeVideoDst DiaryResourceTypeDst = 2 |
| 18 | + // Ours类型 |
| 19 | + DiaryResourceType_DiaryResourceTypeOursDst DiaryResourceTypeDst = 3 |
| 20 | +) |
| 21 | + |
| 22 | +type SquareDiaryItemDst struct { |
| 23 | + // 资源类型 |
| 24 | + ResourceType DiaryResourceTypeDst `protobuf:"varint,7,opt,name=ResourceType,proto3,enum=topic.v1.DiaryResourceType" json:"ResourceType,omitempty"` |
| 25 | + // 资源链接数组 |
| 26 | +} |
| 27 | + |
| 28 | +type GetRecommendedListResp_GetRecommendedListRespData struct { |
| 29 | + |
| 30 | + // 列表 |
| 31 | + List []*SquareDiaryItemDst `protobuf:"bytes,1,rep,name=List,proto3" json:"List,omitempty"` |
| 32 | + // 是否有更多记录 |
| 33 | + HasMore bool `protobuf:"varint,2,opt,name=HasMore,proto3" json:"HasMore,omitempty"` |
| 34 | + // 记录位置 |
| 35 | + Pos int32 `protobuf:"varint,3,opt,name=Pos,proto3" json:"Pos,omitempty"` |
| 36 | + // 相同记录的偏移量 |
| 37 | + Offset int32 `protobuf:"varint,4,opt,name=Offset,proto3" json:"Offset,omitempty"` |
| 38 | +} |
| 39 | + |
| 40 | +type DiaryResourceTypeSrc int32 |
| 41 | + |
| 42 | +const ( |
| 43 | + // 文本 |
| 44 | + DiaryResourceType_DiaryResourceTypeText DiaryResourceTypeSrc = 0 |
| 45 | + // 图片 |
| 46 | + DiaryResourceType_DiaryResourceTypeImage DiaryResourceTypeSrc = 1 |
| 47 | + // 视频 |
| 48 | + DiaryResourceType_DiaryResourceTypeVideo DiaryResourceTypeSrc = 2 |
| 49 | + // Ours类型 |
| 50 | + DiaryResourceType_DiaryResourceTypeOurs DiaryResourceTypeSrc = 3 |
| 51 | +) |
| 52 | + |
| 53 | +type SquareDiaryItemSrc struct { |
| 54 | + // 资源类型 |
| 55 | + ResourceType DiaryResourceTypeSrc `protobuf:"varint,7,opt,name=ResourceType,proto3,enum=topic.v1.DiaryResourceType" json:"ResourceType,omitempty"` |
| 56 | + // 资源链接数组 |
| 57 | +} |
| 58 | + |
| 59 | +type GetRecommendedListResp struct { |
| 60 | + // 列表 |
| 61 | + List []*SquareDiaryItemSrc `protobuf:"bytes,1,rep,name=List,proto3" json:"List,omitempty"` |
| 62 | + // 是否有更多记录 |
| 63 | + HasMore bool `protobuf:"varint,2,opt,name=HasMore,proto3" json:"HasMore,omitempty"` |
| 64 | + // 记录位置 |
| 65 | + Pos int32 `protobuf:"varint,3,opt,name=Pos,proto3" json:"Pos,omitempty"` |
| 66 | + // 相同记录的偏移量 |
| 67 | + Offset int32 `protobuf:"varint,4,opt,name=Offset,proto3" json:"Offset,omitempty"` |
| 68 | +} |
| 69 | + |
| 70 | +func Test_Fix2(t *testing.T) { |
| 71 | + |
| 72 | + var r *GetRecommendedListResp_GetRecommendedListRespData |
| 73 | + resp := GetRecommendedListResp{ |
| 74 | + // 帮我优化这个代码 |
| 75 | + List: []*SquareDiaryItemSrc{&SquareDiaryItemSrc{ResourceType: DiaryResourceType_DiaryResourceTypeVideo}}, |
| 76 | + HasMore: true, |
| 77 | + Pos: 10, |
| 78 | + Offset: 11, |
| 79 | + } |
| 80 | + err := Copy(&r, &resp).Do() |
| 81 | + assert.NoError(t, err) |
| 82 | + assert.NotEqual(t, r, nil) |
| 83 | + assert.NotEqual(t, len(r.List), 0) |
| 84 | +} |
0 commit comments