[#222] Support Inhume and Delete in object service
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
21708d5408
commit
351e4b4592
5 changed files with 46 additions and 20 deletions
|
@ -23,7 +23,7 @@ type cfg struct {
|
|||
|
||||
// DeleteHandler is an interface of delete queue processor.
|
||||
type DeleteHandler interface {
|
||||
DeleteObjects(...*object.Address)
|
||||
DeleteObjects(*object.Address, ...*object.Address)
|
||||
}
|
||||
|
||||
var errNilObject = errors.New("object is nil")
|
||||
|
@ -108,14 +108,14 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error {
|
|||
}
|
||||
|
||||
// ValidateContent validates payload content according to object type.
|
||||
func (v *FormatValidator) ValidateContent(t object.Type, payload []byte) error {
|
||||
switch t {
|
||||
func (v *FormatValidator) ValidateContent(o *object.Object) error {
|
||||
switch o.Type() {
|
||||
case object.TypeTombstone:
|
||||
if len(payload) == 0 {
|
||||
if len(o.Payload()) == 0 {
|
||||
return errors.Errorf("(%T) empty payload in tombstone", v)
|
||||
}
|
||||
|
||||
content, err := TombstoneContentFromBytes(payload)
|
||||
content, err := TombstoneContentFromBytes(o.Payload())
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not parse tombstone content", err)
|
||||
}
|
||||
|
@ -128,8 +128,12 @@ func (v *FormatValidator) ValidateContent(t object.Type, payload []byte) error {
|
|||
}
|
||||
}
|
||||
|
||||
tsAddr := new(object.Address)
|
||||
tsAddr.SetContainerID(o.ContainerID())
|
||||
tsAddr.SetObjectID(o.ID())
|
||||
|
||||
if v.deleteHandler != nil {
|
||||
v.deleteHandler.DeleteObjects(addrList...)
|
||||
v.deleteHandler.DeleteObjects(tsAddr, addrList...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,10 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("tombstone content", func(t *testing.T) {
|
||||
require.Error(t, v.ValidateContent(object.TypeTombstone, nil))
|
||||
obj := NewRaw()
|
||||
obj.SetType(object.TypeTombstone)
|
||||
|
||||
require.Error(t, v.ValidateContent(obj.Object().SDK()))
|
||||
|
||||
addr := object.NewAddress()
|
||||
|
||||
|
@ -115,7 +118,9 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
data, err := content.MarshalBinary()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Error(t, v.ValidateContent(object.TypeTombstone, data))
|
||||
obj.SetPayload(data)
|
||||
|
||||
require.Error(t, v.ValidateContent(obj.Object().SDK()))
|
||||
|
||||
addr.SetContainerID(testContainerID(t))
|
||||
addr.SetObjectID(testObjectID(t))
|
||||
|
@ -123,6 +128,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
data, err = content.MarshalBinary()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, v.ValidateContent(object.TypeTombstone, data))
|
||||
obj.SetPayload(data)
|
||||
|
||||
require.NoError(t, v.ValidateContent(obj.Object().SDK()))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue