diff --git a/pkg/container/id/id.go b/pkg/container/id/id.go index 46b8d371..b09c7b33 100644 --- a/pkg/container/id/id.go +++ b/pkg/container/id/id.go @@ -13,6 +13,8 @@ import ( type ID refs.ContainerID // NewFromV2 wraps v2 ContainerID message to ID. +// +// Nil refs.ContainerID converts to nil. func NewFromV2(idV2 *refs.ContainerID) *ID { return (*ID)(idV2) } @@ -28,6 +30,8 @@ func (id *ID) SetSHA256(v [sha256.Size]byte) { } // ToV2 returns the v2 container ID message. +// +// Nil Result converts to nil. func (id *ID) ToV2() *refs.ContainerID { return (*refs.ContainerID)(id) } diff --git a/pkg/container/id/id_test.go b/pkg/container/id/id_test.go index 6aeca3c8..e0a266ee 100644 --- a/pkg/container/id/id_test.go +++ b/pkg/container/id/id_test.go @@ -7,6 +7,7 @@ import ( cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" + "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/stretchr/testify/require" ) @@ -16,13 +17,22 @@ func randSHA256Checksum() (cs [sha256.Size]byte) { } func TestID_ToV2(t *testing.T) { - checksum := randSHA256Checksum() + t.Run("non-nil", func(t *testing.T) { + checksum := randSHA256Checksum() - id := cidtest.GenerateWithChecksum(checksum) + id := cidtest.GenerateWithChecksum(checksum) - idV2 := id.ToV2() + idV2 := id.ToV2() - require.Equal(t, id, cid.NewFromV2(idV2)) + require.Equal(t, id, cid.NewFromV2(idV2)) + require.Equal(t, checksum[:], idV2.GetValue()) + }) + + t.Run("nil", func(t *testing.T) { + var x *cid.ID + + require.Nil(t, x.ToV2()) + }) } func TestID_Equal(t *testing.T) { @@ -69,3 +79,11 @@ func TestContainerIDEncoding(t *testing.T) { require.Equal(t, id, a2) }) } + +func TestNewFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *refs.ContainerID + + require.Nil(t, cid.NewFromV2(x)) + }) +}