[#321] pkg/container: Remove no longer use NewVerifiedFromV2 func
Also remove `pkg.IsSupportedVersion` used by `NewVerifiedFromV2` only. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d809155efa
commit
4331646615
4 changed files with 0 additions and 121 deletions
|
@ -1,28 +0,0 @@
|
||||||
package container
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewVerifiedFromV2 constructs Container from NeoFS API V2 Container message.
|
|
||||||
// Returns error if message does not meet NeoFS API V2 specification.
|
|
||||||
//
|
|
||||||
// Additionally checks if message carries supported version.
|
|
||||||
func NewVerifiedFromV2(cnrV2 *container.Container) (*Container, error) {
|
|
||||||
cnr := NewContainerFromV2(cnrV2)
|
|
||||||
|
|
||||||
// check version support
|
|
||||||
if err := pkg.IsSupportedVersion(cnr.Version()); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check nonce format
|
|
||||||
if _, err := cnr.NonceUUID(); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid nonce: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cnr, nil
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package container_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
||||||
containerV2 "github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewVerifiedFromV2(t *testing.T) {
|
|
||||||
cnrV2 := new(containerV2.Container)
|
|
||||||
|
|
||||||
errAssert := func() {
|
|
||||||
_, err := container.NewVerifiedFromV2(cnrV2)
|
|
||||||
require.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set unsupported version
|
|
||||||
v := pkg.SDKVersion()
|
|
||||||
v.SetMajor(0)
|
|
||||||
require.Error(t, pkg.IsSupportedVersion(v))
|
|
||||||
cnrV2.SetVersion(v.ToV2())
|
|
||||||
|
|
||||||
errAssert()
|
|
||||||
|
|
||||||
// set supported version
|
|
||||||
v.SetMajor(2)
|
|
||||||
require.NoError(t, pkg.IsSupportedVersion(v))
|
|
||||||
cnrV2.SetVersion(v.ToV2())
|
|
||||||
|
|
||||||
errAssert()
|
|
||||||
|
|
||||||
// set invalid nonce
|
|
||||||
nonce := []byte{1, 2, 3}
|
|
||||||
cnrV2.SetNonce(nonce)
|
|
||||||
|
|
||||||
errAssert()
|
|
||||||
|
|
||||||
// set valid nonce
|
|
||||||
uid := uuid.New()
|
|
||||||
data, _ := uid.MarshalBinary()
|
|
||||||
cnrV2.SetNonce(data)
|
|
||||||
|
|
||||||
_, err := container.NewVerifiedFromV2(cnrV2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
|
@ -74,17 +74,6 @@ func (v *Version) String() string {
|
||||||
return fmt.Sprintf("v%d.%d", v.Major(), v.Minor())
|
return fmt.Sprintf("v%d.%d", v.Major(), v.Minor())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSupportedVersion returns error if v is not supported by current SDK.
|
|
||||||
func IsSupportedVersion(v *Version) error {
|
|
||||||
mjr, mnr := v.Major(), v.Minor()
|
|
||||||
|
|
||||||
if mjr != 2 || mnr > sdkMnr {
|
|
||||||
return fmt.Errorf("unsupported version %d.%d", mjr, mnr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal marshals Version into a protobuf binary form.
|
// Marshal marshals Version into a protobuf binary form.
|
||||||
//
|
//
|
||||||
// Buffer is allocated when the argument is empty.
|
// Buffer is allocated when the argument is empty.
|
||||||
|
|
|
@ -47,39 +47,6 @@ func TestSDKVersion(t *testing.T) {
|
||||||
require.Equal(t, uint32(sdkMnr), v.Minor())
|
require.Equal(t, uint32(sdkMnr), v.Minor())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsSupportedVersion(t *testing.T) {
|
|
||||||
require.Error(t, IsSupportedVersion(nil))
|
|
||||||
|
|
||||||
v := NewVersion()
|
|
||||||
|
|
||||||
v.SetMajor(1)
|
|
||||||
require.Error(t, IsSupportedVersion(v))
|
|
||||||
|
|
||||||
v.SetMajor(3)
|
|
||||||
require.Error(t, IsSupportedVersion(v))
|
|
||||||
|
|
||||||
for _, item := range []struct {
|
|
||||||
mjr, maxMnr uint32
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
mjr: 2,
|
|
||||||
maxMnr: sdkMnr,
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
v.SetMajor(item.mjr)
|
|
||||||
|
|
||||||
for i := uint32(0); i <= item.maxMnr; i++ {
|
|
||||||
v.SetMinor(i)
|
|
||||||
|
|
||||||
require.NoError(t, IsSupportedVersion(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
v.SetMinor(item.maxMnr + 1)
|
|
||||||
|
|
||||||
require.Error(t, IsSupportedVersion(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestVersionEncoding(t *testing.T) {
|
func TestVersionEncoding(t *testing.T) {
|
||||||
v := NewVersion()
|
v := NewVersion()
|
||||||
v.SetMajor(1)
|
v.SetMajor(1)
|
||||||
|
|
Loading…
Reference in a new issue