diff --git a/netmap/node_info.go b/netmap/node_info.go index bd37388..c79696e 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -460,6 +460,8 @@ func (x *NodeInfo) SortAttributes() { // SetOffline sets the state of the node to "offline". When a node updates // information about itself in the network map, this action is interpreted as // an intention to leave the network. +// +// See also IsOffline. func (x *NodeInfo) SetOffline() { x.m.SetState(netmap.Offline) } @@ -470,6 +472,8 @@ func (x *NodeInfo) SetOffline() { // mean online). // // See also SetOffline. +// +// Deprecated: use Status instead. func (x NodeInfo) IsOffline() bool { return x.m.GetState() == netmap.Offline } @@ -489,6 +493,8 @@ func (x *NodeInfo) SetOnline() { // mean offline). // // See also SetOnline. +// +// Deprecated: use Status instead. func (x NodeInfo) IsOnline() bool { return x.m.GetState() == netmap.Online } @@ -507,6 +513,15 @@ func (x *NodeInfo) SetMaintenance() { // Zero NodeInfo has undefined state. // // See also SetMaintenance. +// +// Deprecated: use Status instead. func (x NodeInfo) IsMaintenance() bool { return x.m.GetState() == netmap.Maintenance } + +// Status returns the current state of the node in the network map. +// +// Zero NodeInfo has an undefined state, neither online nor offline. +func (x NodeInfo) Status() netmap.NodeState { + return x.m.GetState() +} diff --git a/netmap/node_info_test.go b/netmap/node_info_test.go index 1d1c018..3b4ed3d 100644 --- a/netmap/node_info_test.go +++ b/netmap/node_info_test.go @@ -3,6 +3,7 @@ package netmap import ( "testing" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" "github.com/stretchr/testify/require" ) @@ -30,20 +31,36 @@ func TestNodeInfo_Status(t *testing.T) { require.False(t, n.IsOffline()) require.False(t, n.IsMaintenance()) + require.NotEqual(t, netmap.Online, n.Status()) + require.NotEqual(t, netmap.Offline, n.Status()) + require.NotEqual(t, netmap.Maintenance, n.Status()) + n.SetOnline() require.True(t, n.IsOnline()) require.False(t, n.IsOffline()) require.False(t, n.IsMaintenance()) + require.Equal(t, netmap.Online, n.Status()) + require.NotEqual(t, netmap.Offline, n.Status()) + require.NotEqual(t, netmap.Maintenance, n.Status()) + n.SetOffline() require.True(t, n.IsOffline()) require.False(t, n.IsOnline()) require.False(t, n.IsMaintenance()) + require.NotEqual(t, netmap.Online, n.Status()) + require.Equal(t, netmap.Offline, n.Status()) + require.NotEqual(t, netmap.Maintenance, n.Status()) + n.SetMaintenance() require.True(t, n.IsMaintenance()) require.False(t, n.IsOnline()) require.False(t, n.IsOffline()) + + require.NotEqual(t, netmap.Online, n.Status()) + require.NotEqual(t, netmap.Offline, n.Status()) + require.Equal(t, netmap.Maintenance, n.Status()) } func TestNodeInfo_ExternalAddr(t *testing.T) {