frostfs-sdk-go/object/lock_test.go
Leonard Lyubich 1c161956c8 [#163] object: Implement functions linking Object and Lock instances
Add `WriteLock`/`ReadLock` function which writes/read `Lock` instace
to/from the `Object` instance.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-03-05 17:38:16 +03:00

39 lines
693 B
Go

package object_test
import (
"testing"
"github.com/nspcc-dev/neofs-sdk-go/object"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
"github.com/stretchr/testify/require"
)
func TestLockEncoding(t *testing.T) {
l := *objecttest.Lock()
t.Run("binary", func(t *testing.T) {
data := l.Marshal()
var l2 object.Lock
require.NoError(t, l2.Unmarshal(data))
require.Equal(t, l, l2)
})
}
func TestWriteLock(t *testing.T) {
l := *objecttest.Lock()
var o object.Object
object.WriteLock(&o, l)
var l2 object.Lock
require.NoError(t, object.ReadLock(&l2, o))
require.Equal(t, l, l2)
// corrupt payload
o.Payload()[0]++
require.Error(t, object.ReadLock(&l2, o))
}