forked from TrueCloudLab/frostfs-api-go
accounting: implement SignedDataSource on DeleteRequest message
This commit is contained in:
parent
81f537cda8
commit
3fb293543f
4 changed files with 129 additions and 0 deletions
|
@ -152,3 +152,41 @@ func (m ListRequest) ReadSignedData(p []byte) (int, error) {
|
|||
|
||||
return sz, nil
|
||||
}
|
||||
|
||||
// SignedData returns payload bytes of the request.
|
||||
func (m DeleteRequest) SignedData() ([]byte, error) {
|
||||
data := make([]byte, m.SignedDataSize())
|
||||
|
||||
if _, err := m.ReadSignedData(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// SignedDataSize returns payload size of the request.
|
||||
func (m DeleteRequest) SignedDataSize() int {
|
||||
return 0 +
|
||||
m.GetID().Size() +
|
||||
m.GetOwnerID().Size() +
|
||||
m.GetMessageID().Size()
|
||||
}
|
||||
|
||||
// ReadSignedData copies payload bytes to passed buffer.
|
||||
//
|
||||
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
||||
func (m DeleteRequest) ReadSignedData(p []byte) (int, error) {
|
||||
if len(p) < m.SignedDataSize() {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var off int
|
||||
|
||||
off += copy(p[off:], m.GetID().Bytes())
|
||||
|
||||
off += copy(p[off:], m.GetOwnerID().Bytes())
|
||||
|
||||
off += copy(p[off:], m.GetMessageID().Bytes())
|
||||
|
||||
return off, nil
|
||||
}
|
||||
|
|
|
@ -119,6 +119,37 @@ func TestSignBalanceRequest(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
constructor: func() sigType {
|
||||
return new(DeleteRequest)
|
||||
},
|
||||
payloadCorrupt: []func(sigType){
|
||||
func(s sigType) {
|
||||
req := s.(*DeleteRequest)
|
||||
|
||||
id, err := NewChequeID()
|
||||
require.NoError(t, err)
|
||||
|
||||
req.SetID(id)
|
||||
},
|
||||
func(s sigType) {
|
||||
req := s.(*DeleteRequest)
|
||||
|
||||
owner := req.GetOwnerID()
|
||||
owner[0]++
|
||||
|
||||
req.SetOwnerID(owner)
|
||||
},
|
||||
func(s sigType) {
|
||||
req := s.(*DeleteRequest)
|
||||
|
||||
mid := req.GetMessageID()
|
||||
mid[0]++
|
||||
|
||||
req.SetMessageID(mid)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
|
|
|
@ -421,3 +421,33 @@ func (m ListRequest) GetOwnerID() OwnerID {
|
|||
func (m *ListRequest) SetOwnerID(id OwnerID) {
|
||||
m.OwnerID = id
|
||||
}
|
||||
|
||||
// GetID is an ID field getter.
|
||||
func (m DeleteRequest) GetID() ChequeID {
|
||||
return m.ID
|
||||
}
|
||||
|
||||
// SetID is an ID field setter.
|
||||
func (m *DeleteRequest) SetID(id ChequeID) {
|
||||
m.ID = id
|
||||
}
|
||||
|
||||
// GetOwnerID is an OwnerID field getter.
|
||||
func (m DeleteRequest) GetOwnerID() OwnerID {
|
||||
return m.OwnerID
|
||||
}
|
||||
|
||||
// SetOwnerID is an OwnerID field setter.
|
||||
func (m *DeleteRequest) SetOwnerID(id OwnerID) {
|
||||
m.OwnerID = id
|
||||
}
|
||||
|
||||
// GetMessageID is a MessageID field getter.
|
||||
func (m DeleteRequest) GetMessageID() MessageID {
|
||||
return m.MessageID
|
||||
}
|
||||
|
||||
// SetMessageID is a MessageID field setter.
|
||||
func (m *DeleteRequest) SetMessageID(id MessageID) {
|
||||
m.MessageID = id
|
||||
}
|
||||
|
|
|
@ -161,3 +161,33 @@ func TestListRequestGettersSetters(t *testing.T) {
|
|||
|
||||
require.Equal(t, ownerID, m.GetOwnerID())
|
||||
}
|
||||
|
||||
func TestDeleteRequestGettersSetters(t *testing.T) {
|
||||
t.Run("id", func(t *testing.T) {
|
||||
id := ChequeID("test id")
|
||||
m := new(DeleteRequest)
|
||||
|
||||
m.SetID(id)
|
||||
|
||||
require.Equal(t, id, m.GetID())
|
||||
})
|
||||
|
||||
t.Run("owner", func(t *testing.T) {
|
||||
id := OwnerID{1, 2, 3}
|
||||
m := new(DeleteRequest)
|
||||
|
||||
m.SetOwnerID(id)
|
||||
|
||||
require.Equal(t, id, m.GetOwnerID())
|
||||
})
|
||||
|
||||
t.Run("message ID", func(t *testing.T) {
|
||||
id, err := refs.NewUUID()
|
||||
require.NoError(t, err)
|
||||
|
||||
m := new(DeleteRequest)
|
||||
m.SetMessageID(id)
|
||||
|
||||
require.Equal(t, id, m.GetMessageID())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue