forked from TrueCloudLab/frostfs-sdk-go
[#172] object: Allow to marshal SplitInfo
to JSON
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7d19718e1d
commit
3e12d0eb69
2 changed files with 25 additions and 0 deletions
|
@ -65,3 +65,13 @@ func (s *SplitInfo) Marshal() ([]byte, error) {
|
|||
func (s *SplitInfo) Unmarshal(data []byte) error {
|
||||
return (*object.SplitInfo)(s).Unmarshal(data)
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s *SplitInfo) MarshalJSON() ([]byte, error) {
|
||||
return (*object.SplitInfo)(s).MarshalJSON()
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *SplitInfo) UnmarshalJSON(data []byte) error {
|
||||
return (*object.SplitInfo)(s).UnmarshalJSON(data)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package object_test
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
objv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
|
@ -87,3 +88,17 @@ func TestNewSplitInfo(t *testing.T) {
|
|||
require.Nil(t, siV2.GetLink())
|
||||
})
|
||||
}
|
||||
|
||||
func TestSplitInfoMarshalJSON(t *testing.T) {
|
||||
s := object.NewSplitInfo()
|
||||
s.SetSplitID(object.NewSplitID())
|
||||
s.SetLastPart(generateID())
|
||||
s.SetLink(generateID())
|
||||
|
||||
data, err := s.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
actual := object.NewSplitInfo()
|
||||
require.NoError(t, json.Unmarshal(data, actual))
|
||||
require.Equal(t, s, actual)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue