[#97] object: Refactor Patch related structs
* Add getters and setters for related types; * Fix unit-tests. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
8ce8cd6ec2
commit
8609f29a60
4 changed files with 111 additions and 39 deletions
|
@ -2392,10 +2392,10 @@ func (r *PatchRequestBody) ToGRPCMessage() grpc.Message {
|
|||
if r != nil {
|
||||
m = new(object.PatchRequest_Body)
|
||||
|
||||
m.SetAddress(r.Address.ToGRPCMessage().(*refsGRPC.Address))
|
||||
m.SetNewAttributes(AttributesToGRPC(r.NewAttributes))
|
||||
m.SetReplaceAttributes(r.ReplaceAttributes)
|
||||
m.SetPatch(r.Patch.ToGRPCMessage().(*object.PatchRequest_Body_Patch))
|
||||
m.SetAddress(r.address.ToGRPCMessage().(*refsGRPC.Address))
|
||||
m.SetNewAttributes(AttributesToGRPC(r.newAttributes))
|
||||
m.SetReplaceAttributes(r.replaceAttributes)
|
||||
m.SetPatch(r.patch.ToGRPCMessage().(*object.PatchRequest_Body_Patch))
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -2411,34 +2411,34 @@ func (r *PatchRequestBody) FromGRPCMessage(m grpc.Message) error {
|
|||
|
||||
addr := v.GetAddress()
|
||||
if addr == nil {
|
||||
r.Address = nil
|
||||
r.address = nil
|
||||
} else {
|
||||
if r.Address == nil {
|
||||
r.Address = new(refs.Address)
|
||||
if r.address == nil {
|
||||
r.address = new(refs.Address)
|
||||
}
|
||||
|
||||
err = r.Address.FromGRPCMessage(addr)
|
||||
err = r.address.FromGRPCMessage(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
r.NewAttributes, err = AttributesFromGRPC(v.GetNewAttributes())
|
||||
r.newAttributes, err = AttributesFromGRPC(v.GetNewAttributes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.ReplaceAttributes = v.GetReplaceAttributes()
|
||||
r.replaceAttributes = v.GetReplaceAttributes()
|
||||
|
||||
patch := v.GetPatch()
|
||||
if patch == nil {
|
||||
r.Patch = nil
|
||||
r.patch = nil
|
||||
} else {
|
||||
if r.Patch == nil {
|
||||
r.Patch = new(PatchRequestBodyPatch)
|
||||
if r.patch == nil {
|
||||
r.patch = new(PatchRequestBodyPatch)
|
||||
}
|
||||
|
||||
err = r.Patch.FromGRPCMessage(patch)
|
||||
err = r.patch.FromGRPCMessage(patch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2453,7 +2453,7 @@ func (r *PatchRequest) ToGRPCMessage() grpc.Message {
|
|||
if r != nil {
|
||||
m = new(object.PatchRequest)
|
||||
|
||||
m.SetBody(r.Body.ToGRPCMessage().(*object.PatchRequest_Body))
|
||||
m.SetBody(r.body.ToGRPCMessage().(*object.PatchRequest_Body))
|
||||
r.RequestHeaders.ToMessage(m)
|
||||
}
|
||||
|
||||
|
@ -2470,13 +2470,13 @@ func (r *PatchRequest) FromGRPCMessage(m grpc.Message) error {
|
|||
|
||||
body := v.GetBody()
|
||||
if body == nil {
|
||||
r.Body = nil
|
||||
r.body = nil
|
||||
} else {
|
||||
if r.Body == nil {
|
||||
r.Body = new(PatchRequestBody)
|
||||
if r.body == nil {
|
||||
r.body = new(PatchRequestBody)
|
||||
}
|
||||
|
||||
err = r.Body.FromGRPCMessage(body)
|
||||
err = r.body.FromGRPCMessage(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1367,12 +1367,12 @@ func (r *PatchRequestBody) StableMarshal(buf []byte) []byte {
|
|||
}
|
||||
|
||||
var offset int
|
||||
offset += proto.NestedStructureMarshal(patchRequestBodyAddrField, buf[offset:], r.Address)
|
||||
for i := range r.NewAttributes {
|
||||
offset += proto.NestedStructureMarshal(patchRequestBodyNewAttrsField, buf[offset:], &r.NewAttributes[i])
|
||||
offset += proto.NestedStructureMarshal(patchRequestBodyAddrField, buf[offset:], r.address)
|
||||
for i := range r.newAttributes {
|
||||
offset += proto.NestedStructureMarshal(patchRequestBodyNewAttrsField, buf[offset:], &r.newAttributes[i])
|
||||
}
|
||||
offset += proto.BoolMarshal(patchRequestBodyReplaceAttrField, buf[offset:], r.ReplaceAttributes)
|
||||
proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.Patch)
|
||||
offset += proto.BoolMarshal(patchRequestBodyReplaceAttrField, buf[offset:], r.replaceAttributes)
|
||||
proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.patch)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
@ -1383,12 +1383,12 @@ func (r *PatchRequestBody) StableSize() int {
|
|||
}
|
||||
|
||||
var size int
|
||||
size += proto.NestedStructureSize(patchRequestBodyAddrField, r.Address)
|
||||
for i := range r.NewAttributes {
|
||||
size += proto.NestedStructureSize(patchRequestBodyNewAttrsField, &r.NewAttributes[i])
|
||||
size += proto.NestedStructureSize(patchRequestBodyAddrField, r.address)
|
||||
for i := range r.newAttributes {
|
||||
size += proto.NestedStructureSize(patchRequestBodyNewAttrsField, &r.newAttributes[i])
|
||||
}
|
||||
size += proto.BoolSize(patchRequestBodyReplaceAttrField, r.ReplaceAttributes)
|
||||
size += proto.NestedStructureSize(patchRequestBodyPatchField, r.Patch)
|
||||
size += proto.BoolSize(patchRequestBodyReplaceAttrField, r.replaceAttributes)
|
||||
size += proto.NestedStructureSize(patchRequestBodyPatchField, r.patch)
|
||||
|
||||
return size
|
||||
}
|
||||
|
|
|
@ -706,10 +706,10 @@ func GeneratePatchRequestBody(empty bool) *object.PatchRequestBody {
|
|||
m := new(object.PatchRequestBody)
|
||||
|
||||
if !empty {
|
||||
m.Address = refstest.GenerateAddress(empty)
|
||||
m.NewAttributes = GenerateAttributes(empty)
|
||||
m.ReplaceAttributes = false
|
||||
m.Patch = GeneratePatchRequestBodyPatch(empty)
|
||||
m.SetAddress(refstest.GenerateAddress(empty))
|
||||
m.SetNewAttributes(GenerateAttributes(empty))
|
||||
m.SetReplaceAttributes(false)
|
||||
m.SetPatch(GeneratePatchRequestBodyPatch(empty))
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -719,7 +719,7 @@ func GeneratePatchRequest(empty bool) *object.PatchRequest {
|
|||
m := new(object.PatchRequest)
|
||||
|
||||
if !empty {
|
||||
m.Body = GeneratePatchRequestBody(empty)
|
||||
m.SetBody(GeneratePatchRequestBody(empty))
|
||||
}
|
||||
|
||||
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
|
||||
|
|
|
@ -356,17 +356,17 @@ type PatchRequestBodyPatch struct {
|
|||
}
|
||||
|
||||
type PatchRequestBody struct {
|
||||
Address *refs.Address
|
||||
address *refs.Address
|
||||
|
||||
NewAttributes []Attribute
|
||||
newAttributes []Attribute
|
||||
|
||||
ReplaceAttributes bool
|
||||
replaceAttributes bool
|
||||
|
||||
Patch *PatchRequestBodyPatch
|
||||
patch *PatchRequestBodyPatch
|
||||
}
|
||||
|
||||
type PatchRequest struct {
|
||||
Body *PatchRequestBody
|
||||
body *PatchRequestBody
|
||||
|
||||
session.RequestHeaders
|
||||
}
|
||||
|
@ -1543,6 +1543,78 @@ func (r *PutSingleResponse) SetBody(v *PutSingleResponseBody) {
|
|||
r.body = v
|
||||
}
|
||||
|
||||
func (r *PatchRequest) GetBody() *PatchRequestBody {
|
||||
if r != nil {
|
||||
return r.body
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatchRequest) SetBody(v *PatchRequestBody) {
|
||||
r.body = v
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) GetAddress() *refs.Address {
|
||||
if r != nil {
|
||||
return r.address
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) SetAddress(addr *refs.Address) {
|
||||
r.address = addr
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) GetNewAttributes() []Attribute {
|
||||
if r != nil {
|
||||
return r.newAttributes
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) SetNewAttributes(attrs []Attribute) {
|
||||
r.newAttributes = attrs
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) GetReplaceAttributes() bool {
|
||||
if r != nil {
|
||||
return r.replaceAttributes
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) SetReplaceAttributes(replace bool) {
|
||||
r.replaceAttributes = replace
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) GetPatch() *PatchRequestBodyPatch {
|
||||
if r != nil {
|
||||
return r.patch
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatchRequestBody) SetPatch(patch *PatchRequestBodyPatch) {
|
||||
r.patch = patch
|
||||
}
|
||||
|
||||
func (r *PatchResponse) GetBody() *PatchResponseBody {
|
||||
if r != nil {
|
||||
return r.Body
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *PatchResponse) SetBody(v *PatchResponseBody) {
|
||||
r.Body = v
|
||||
}
|
||||
|
||||
func (s *ECInfo) getObjectPart() {}
|
||||
|
||||
func (s *ECInfo) getHeaderPart() {}
|
||||
|
|
Loading…
Reference in a new issue