frostfs-sdk-go/subnet/subnet_test.go
Leonard Lyubich 8175462050 [#79] Implement type for subnet information
Create `subnet` package. Define `Info` type of the subnet info. Support
encoding and transport over the NeoFS API V2 protocol. Add methods to
work with identifier and owner.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-11-25 13:04:24 +03:00

79 lines
1.4 KiB
Go

package subnet_test
import (
"testing"
subnetv2 "github.com/nspcc-dev/neofs-api-go/v2/subnet"
subnettest "github.com/nspcc-dev/neofs-api-go/v2/subnet/test"
"github.com/nspcc-dev/neofs-sdk-go/owner"
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
"github.com/nspcc-dev/neofs-sdk-go/subnet"
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
"github.com/stretchr/testify/require"
)
func TestInfoZero(t *testing.T) {
var info subnet.Info
var id subnetid.ID
info.ReadID(&id)
require.True(t, subnetid.IsZero(id))
require.False(t, info.HasOwner())
}
func TestInfo_SetID(t *testing.T) {
var (
idFrom, idTo subnetid.ID
info subnet.Info
)
idFrom.SetNumber(222)
info.SetID(idFrom)
info.ReadID(&idTo)
require.True(t, idTo.Equals(&idFrom))
}
func TestInfo_SetOwner(t *testing.T) {
var (
idFrom, idTo owner.ID
info subnet.Info
)
idFrom = *ownertest.GenerateID()
require.False(t, info.HasOwner())
info.SetOwner(idFrom)
require.True(t, info.HasOwner())
info.ReadOwner(&idTo)
require.True(t, idTo.Equal(&idFrom))
}
func TestInfo_WriteToV2(t *testing.T) {
var (
infoTo, infoFrom subnet.Info
infoV2From, infoV2To subnetv2.Info
)
infoV2From = *subnettest.GenerateSubnetInfo(false)
infoFrom.FromV2(infoV2From)
infoFrom.WriteToV2(&infoV2To)
infoTo.FromV2(infoV2To)
require.Equal(t, infoV2From, infoV2To)
require.Equal(t, infoFrom, infoTo)
}