2021-10-27 10:00:35 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
|
2021-10-27 10:00:35 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
func TestNodeInfo_SetAttribute(t *testing.T) {
|
|
|
|
var n NodeInfo
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
const key = "some key"
|
2021-10-27 10:00:35 +00:00
|
|
|
val := "some value"
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.Zero(t, n.Attribute(val))
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
n.SetAttribute(key, val)
|
|
|
|
require.Equal(t, val, n.Attribute(key))
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
val = "some other value"
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
n.SetAttribute(key, val)
|
|
|
|
require.Equal(t, val, n.Attribute(key))
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|
2022-09-15 05:51:24 +00:00
|
|
|
|
2024-09-03 14:17:25 +00:00
|
|
|
func TestNodeState(t *testing.T) {
|
|
|
|
m := map[NodeState]netmap.NodeState{
|
|
|
|
UnspecifiedState: netmap.UnspecifiedState,
|
|
|
|
Online: netmap.Online,
|
|
|
|
Offline: netmap.Offline,
|
|
|
|
Maintenance: netmap.Maintenance,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("from sdk to v2", func(t *testing.T) {
|
|
|
|
for stateSDK, stateV2 := range m {
|
|
|
|
require.Equal(t, stateV2, stateSDK.ToV2())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from v2 to sdk", func(t *testing.T) {
|
|
|
|
for stateSDK, stateV2 := range m {
|
|
|
|
var state NodeState
|
|
|
|
state.FromV2(stateV2)
|
|
|
|
require.Equal(t, stateSDK, state)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-09-15 05:51:24 +00:00
|
|
|
|
2024-09-03 14:17:25 +00:00
|
|
|
func TestNodeInfo_Status(t *testing.T) {
|
|
|
|
t.Run("deprecated getters/setters", func(t *testing.T) {
|
|
|
|
var n NodeInfo
|
|
|
|
|
|
|
|
require.False(t, n.IsOnline())
|
|
|
|
require.False(t, n.IsOffline())
|
|
|
|
require.False(t, n.IsMaintenance())
|
|
|
|
|
|
|
|
n.SetOnline()
|
|
|
|
require.True(t, n.IsOnline())
|
|
|
|
require.False(t, n.IsOffline())
|
|
|
|
require.False(t, n.IsMaintenance())
|
|
|
|
|
|
|
|
n.SetOffline()
|
|
|
|
require.True(t, n.IsOffline())
|
|
|
|
require.False(t, n.IsOnline())
|
|
|
|
require.False(t, n.IsMaintenance())
|
|
|
|
|
|
|
|
n.SetMaintenance()
|
|
|
|
require.True(t, n.IsMaintenance())
|
|
|
|
require.False(t, n.IsOnline())
|
|
|
|
require.False(t, n.IsOffline())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("brand new getters/setters", func(t *testing.T) {
|
|
|
|
var n NodeInfo
|
|
|
|
|
|
|
|
require.False(t, n.Status().IsOnline())
|
|
|
|
require.False(t, n.Status().IsOffline())
|
|
|
|
require.False(t, n.Status().IsMaintenance())
|
|
|
|
|
|
|
|
n.SetStatus(Online)
|
|
|
|
require.True(t, n.Status().IsOnline())
|
|
|
|
require.False(t, n.Status().IsOffline())
|
|
|
|
require.False(t, n.Status().IsMaintenance())
|
|
|
|
|
|
|
|
n.SetStatus(Offline)
|
|
|
|
require.False(t, n.Status().IsOnline())
|
|
|
|
require.True(t, n.Status().IsOffline())
|
|
|
|
require.False(t, n.Status().IsMaintenance())
|
|
|
|
|
|
|
|
n.SetStatus(Maintenance)
|
|
|
|
require.False(t, n.Status().IsOnline())
|
|
|
|
require.False(t, n.Status().IsOffline())
|
|
|
|
require.True(t, n.Status().IsMaintenance())
|
|
|
|
})
|
2022-09-15 05:51:24 +00:00
|
|
|
}
|
2022-09-24 10:37:08 +00:00
|
|
|
|
|
|
|
func TestNodeInfo_ExternalAddr(t *testing.T) {
|
|
|
|
var n NodeInfo
|
|
|
|
|
|
|
|
require.Empty(t, n.ExternalAddresses())
|
|
|
|
require.Panics(t, func() { n.SetExternalAddresses() })
|
|
|
|
|
|
|
|
addr := []string{"1", "2", "3"}
|
|
|
|
n.SetExternalAddresses(addr[0])
|
|
|
|
require.Equal(t, addr[:1], n.ExternalAddresses())
|
|
|
|
|
|
|
|
n.SetExternalAddresses(addr[1:]...)
|
|
|
|
require.Equal(t, addr[1:], n.ExternalAddresses())
|
|
|
|
}
|