[#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:
Airat Arifullin 2024-07-30 17:49:45 +03:00
parent 8ce8cd6ec2
commit 8609f29a60
4 changed files with 111 additions and 39 deletions

View file

@ -2392,10 +2392,10 @@ func (r *PatchRequestBody) ToGRPCMessage() grpc.Message {
if r != nil { if r != nil {
m = new(object.PatchRequest_Body) m = new(object.PatchRequest_Body)
m.SetAddress(r.Address.ToGRPCMessage().(*refsGRPC.Address)) m.SetAddress(r.address.ToGRPCMessage().(*refsGRPC.Address))
m.SetNewAttributes(AttributesToGRPC(r.NewAttributes)) m.SetNewAttributes(AttributesToGRPC(r.newAttributes))
m.SetReplaceAttributes(r.ReplaceAttributes) m.SetReplaceAttributes(r.replaceAttributes)
m.SetPatch(r.Patch.ToGRPCMessage().(*object.PatchRequest_Body_Patch)) m.SetPatch(r.patch.ToGRPCMessage().(*object.PatchRequest_Body_Patch))
} }
return m return m
@ -2411,34 +2411,34 @@ func (r *PatchRequestBody) FromGRPCMessage(m grpc.Message) error {
addr := v.GetAddress() addr := v.GetAddress()
if addr == nil { if addr == nil {
r.Address = nil r.address = nil
} else { } else {
if r.Address == nil { if r.address == nil {
r.Address = new(refs.Address) r.address = new(refs.Address)
} }
err = r.Address.FromGRPCMessage(addr) err = r.address.FromGRPCMessage(addr)
if err != nil { if err != nil {
return err return err
} }
} }
r.NewAttributes, err = AttributesFromGRPC(v.GetNewAttributes()) r.newAttributes, err = AttributesFromGRPC(v.GetNewAttributes())
if err != nil { if err != nil {
return err return err
} }
r.ReplaceAttributes = v.GetReplaceAttributes() r.replaceAttributes = v.GetReplaceAttributes()
patch := v.GetPatch() patch := v.GetPatch()
if patch == nil { if patch == nil {
r.Patch = nil r.patch = nil
} else { } else {
if r.Patch == nil { if r.patch == nil {
r.Patch = new(PatchRequestBodyPatch) r.patch = new(PatchRequestBodyPatch)
} }
err = r.Patch.FromGRPCMessage(patch) err = r.patch.FromGRPCMessage(patch)
if err != nil { if err != nil {
return err return err
} }
@ -2453,7 +2453,7 @@ func (r *PatchRequest) ToGRPCMessage() grpc.Message {
if r != nil { if r != nil {
m = new(object.PatchRequest) m = new(object.PatchRequest)
m.SetBody(r.Body.ToGRPCMessage().(*object.PatchRequest_Body)) m.SetBody(r.body.ToGRPCMessage().(*object.PatchRequest_Body))
r.RequestHeaders.ToMessage(m) r.RequestHeaders.ToMessage(m)
} }
@ -2470,13 +2470,13 @@ func (r *PatchRequest) FromGRPCMessage(m grpc.Message) error {
body := v.GetBody() body := v.GetBody()
if body == nil { if body == nil {
r.Body = nil r.body = nil
} else { } else {
if r.Body == nil { if r.body == nil {
r.Body = new(PatchRequestBody) r.body = new(PatchRequestBody)
} }
err = r.Body.FromGRPCMessage(body) err = r.body.FromGRPCMessage(body)
if err != nil { if err != nil {
return err return err
} }

View file

@ -1367,12 +1367,12 @@ func (r *PatchRequestBody) StableMarshal(buf []byte) []byte {
} }
var offset int var offset int
offset += proto.NestedStructureMarshal(patchRequestBodyAddrField, buf[offset:], r.Address) offset += proto.NestedStructureMarshal(patchRequestBodyAddrField, buf[offset:], r.address)
for i := range r.NewAttributes { for i := range r.newAttributes {
offset += proto.NestedStructureMarshal(patchRequestBodyNewAttrsField, buf[offset:], &r.NewAttributes[i]) offset += proto.NestedStructureMarshal(patchRequestBodyNewAttrsField, buf[offset:], &r.newAttributes[i])
} }
offset += proto.BoolMarshal(patchRequestBodyReplaceAttrField, buf[offset:], r.ReplaceAttributes) offset += proto.BoolMarshal(patchRequestBodyReplaceAttrField, buf[offset:], r.replaceAttributes)
proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.Patch) proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.patch)
return buf return buf
} }
@ -1383,12 +1383,12 @@ func (r *PatchRequestBody) StableSize() int {
} }
var size int var size int
size += proto.NestedStructureSize(patchRequestBodyAddrField, r.Address) size += proto.NestedStructureSize(patchRequestBodyAddrField, r.address)
for i := range r.NewAttributes { for i := range r.newAttributes {
size += proto.NestedStructureSize(patchRequestBodyNewAttrsField, &r.NewAttributes[i]) size += proto.NestedStructureSize(patchRequestBodyNewAttrsField, &r.newAttributes[i])
} }
size += proto.BoolSize(patchRequestBodyReplaceAttrField, r.ReplaceAttributes) size += proto.BoolSize(patchRequestBodyReplaceAttrField, r.replaceAttributes)
size += proto.NestedStructureSize(patchRequestBodyPatchField, r.Patch) size += proto.NestedStructureSize(patchRequestBodyPatchField, r.patch)
return size return size
} }

View file

@ -706,10 +706,10 @@ func GeneratePatchRequestBody(empty bool) *object.PatchRequestBody {
m := new(object.PatchRequestBody) m := new(object.PatchRequestBody)
if !empty { if !empty {
m.Address = refstest.GenerateAddress(empty) m.SetAddress(refstest.GenerateAddress(empty))
m.NewAttributes = GenerateAttributes(empty) m.SetNewAttributes(GenerateAttributes(empty))
m.ReplaceAttributes = false m.SetReplaceAttributes(false)
m.Patch = GeneratePatchRequestBodyPatch(empty) m.SetPatch(GeneratePatchRequestBodyPatch(empty))
} }
return m return m
@ -719,7 +719,7 @@ func GeneratePatchRequest(empty bool) *object.PatchRequest {
m := new(object.PatchRequest) m := new(object.PatchRequest)
if !empty { if !empty {
m.Body = GeneratePatchRequestBody(empty) m.SetBody(GeneratePatchRequestBody(empty))
} }
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))

View file

@ -356,17 +356,17 @@ type PatchRequestBodyPatch struct {
} }
type PatchRequestBody 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 { type PatchRequest struct {
Body *PatchRequestBody body *PatchRequestBody
session.RequestHeaders session.RequestHeaders
} }
@ -1543,6 +1543,78 @@ func (r *PutSingleResponse) SetBody(v *PutSingleResponseBody) {
r.body = v 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) getObjectPart() {}
func (s *ECInfo) getHeaderPart() {} func (s *ECInfo) getHeaderPart() {}