[#283] pkg/owner: Implement Equal method of ID type

Implement `owner.ID.Equal` method which defines a comparison relationship
between two identifiers.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-28 10:25:30 +03:00 committed by Leonard Lyubich
parent 4f286f5175
commit 5fe5af5bf9
2 changed files with 32 additions and 1 deletions

View file

@ -1,4 +1,4 @@
package owner
package owner_test
import (
"crypto/rand"
@ -6,6 +6,8 @@ import (
"testing"
"github.com/mr-tron/base58"
. "github.com/nspcc-dev/neofs-api-go/pkg/owner"
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
"github.com/nspcc-dev/neofs-crypto/test"
"github.com/stretchr/testify/require"
)
@ -93,3 +95,21 @@ func TestIDEncoding(t *testing.T) {
require.Equal(t, id, a2)
})
}
func TestID_Equal(t *testing.T) {
var (
data1 = []byte{1, 2, 3}
data2 = data1
data3 = append(data1, 255)
)
id1 := ownertest.GenerateFromBytes(data1)
require.True(t, id1.Equal(
ownertest.GenerateFromBytes(data2),
))
require.False(t, id1.Equal(
ownertest.GenerateFromBytes(data3),
))
}