2021-10-27 10:00:35 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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
|
|
|
|
|
|
|
func TestNodeInfo_Status(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())
|
|
|
|
}
|
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())
|
|
|
|
}
|