frostfs-node/pkg/innerring/processors/netmap/nodevalidation/state/validator_test.go
Leonard Lyubich 8858840751 [#1796] ir/netmap: Allow to call AddPeer with ONLINE state only
In previous implementation Inner Ring allowed storage nodes with any
state to register in the network. According to the current design, only
nodes with ONLINE state are allowed to enter the network map.

Create new `state` sub-package of `nodevalidation` package of Inner Ring
application. Define `state.NetMapCandidateValidator` type and provide
`NodeValidator` interface required by the Inner Ring's processor of
`Netmap` contract's notification events. Embed new validator into the
one used by the Inner Ring application.

From now all `AddPeer` notifications with node state other than `ONLINE`
will be denied.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-10-05 11:41:49 +03:00

54 lines
1.2 KiB
Go

package state_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/state"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/stretchr/testify/require"
)
func TestValidator_VerifyAndUpdate(t *testing.T) {
var v state.NetMapCandidateValidator
for _, testCase := range []struct {
name string
preparer func(*netmap.NodeInfo) // modifies zero instance
valid bool // is node valid after preparation
}{
{
name: "UNDEFINED",
preparer: func(info *netmap.NodeInfo) {},
valid: false,
},
{
name: "ONLINE",
preparer: (*netmap.NodeInfo).SetOnline,
valid: true,
},
{
name: "OFFLINE",
preparer: (*netmap.NodeInfo).SetOffline,
valid: false,
},
} {
var node netmap.NodeInfo
// prepare node
testCase.preparer(&node)
// save binary representation for mutation check
binNode := node.Marshal()
err := v.VerifyAndUpdate(&node)
if testCase.valid {
require.NoError(t, err, testCase.name)
} else {
require.Error(t, err, testCase.name)
}
// check mutation
require.Equal(t, binNode, node.Marshal(), testCase.name)
}
}