2021-11-26 12:19:20 +00:00
|
|
|
package subnetevents
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
|
|
|
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
|
2021-11-26 12:19:20 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/subnet"
|
|
|
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
|
|
|
)
|
|
|
|
|
|
|
|
type put struct {
|
|
|
|
idEvent
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
creator user.ID
|
2021-11-26 12:19:20 +00:00
|
|
|
|
|
|
|
creatorErr error
|
|
|
|
|
|
|
|
info subnet.Info
|
|
|
|
|
|
|
|
infoErr error
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
func (x put) ReadCreator(id *user.ID) error {
|
2021-11-26 12:19:20 +00:00
|
|
|
if x.creatorErr != nil {
|
|
|
|
return x.creatorErr
|
|
|
|
}
|
|
|
|
|
|
|
|
*id = x.creator
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x put) ReadInfo(info *subnet.Info) error {
|
|
|
|
if x.infoErr != nil {
|
|
|
|
return x.infoErr
|
|
|
|
}
|
|
|
|
|
|
|
|
*info = x.info
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutValidator_Assert(t *testing.T) {
|
|
|
|
var (
|
|
|
|
v PutValidator
|
|
|
|
|
|
|
|
e put
|
|
|
|
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// read ID error
|
|
|
|
e.idErr = errors.New("id err")
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorIs(t, err, e.idErr)
|
|
|
|
|
|
|
|
e.idErr = nil
|
|
|
|
|
|
|
|
// zero subnet ID
|
|
|
|
subnetid.MakeZero(&e.id)
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorAs(t, err, new(zeroSubnetOp))
|
|
|
|
|
|
|
|
const idNum = 13
|
|
|
|
e.id.SetNumber(idNum)
|
|
|
|
|
|
|
|
// read creator error
|
|
|
|
e.creatorErr = errors.New("creator err")
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorIs(t, err, e.creatorErr)
|
|
|
|
|
|
|
|
e.creatorErr = nil
|
|
|
|
|
|
|
|
// read info error
|
|
|
|
e.infoErr = errors.New("info err")
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorIs(t, err, e.infoErr)
|
|
|
|
|
|
|
|
e.infoErr = nil
|
|
|
|
|
|
|
|
// diff explicit ID and the one in info
|
|
|
|
var id2 subnetid.ID
|
|
|
|
|
|
|
|
id2.SetNumber(idNum + 1)
|
|
|
|
|
|
|
|
e.info.SetID(id2)
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorIs(t, err, errDiffID)
|
|
|
|
|
|
|
|
e.info.SetID(e.id)
|
|
|
|
|
|
|
|
// diff explicit creator and the one in info
|
2022-05-17 13:59:46 +00:00
|
|
|
creator2 := *usertest.ID()
|
2021-11-26 12:19:20 +00:00
|
|
|
|
|
|
|
e.info.SetOwner(creator2)
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.ErrorIs(t, err, errDiffOwner)
|
|
|
|
|
|
|
|
e.info.SetOwner(e.creator)
|
|
|
|
|
|
|
|
err = v.Assert(e)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|