frostfs-node/cmd/neofs-node/config/node/config_test.go
Leonard Lyubich 163c24a2d2 [#607] cmd/node: Configure group of bootstrap addresses
There is a need to support multiple network addresses of the storage nodes.

Make `BootstrapAddress` to return `network.AddressGroup` (and rename).

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-28 15:52:50 +03:00

75 lines
1.7 KiB
Go

package nodeconfig
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
"github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/stretchr/testify/require"
)
func TestNodeSection(t *testing.T) {
t.Run("defaults", func(t *testing.T) {
empty := configtest.EmptyConfig()
require.PanicsWithError(
t,
errKeyNotSet.Error(),
func() {
Key(empty)
},
)
require.Panics(
t,
func() {
BootstrapAddresses(empty)
},
)
attribute := Attributes(empty)
relay := Relay(empty)
require.Empty(t, attribute)
require.Equal(t, false, relay)
})
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
key := Key(c)
addr := BootstrapAddresses(c)
attributes := Attributes(c)
relay := Relay(c)
wKey := Wallet(c)
var expectedAddr network.AddressGroup
err := expectedAddr.FromIterator(stringAddressGroup([]string{
"s01.neofs.devenv:8080",
"s02.neofs.devenv:8081",
}))
require.NoError(t, err)
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
require.Equal(t, expectedAddr, addr)
require.Equal(t, true, relay)
require.Len(t, attributes, 2)
require.Equal(t, "Price:11", attributes[0])
require.Equal(t, "UN-LOCODE:RU MSK", attributes[1])
require.NotNil(t, wKey)
require.Equal(t,
config.StringSafe(c.Sub("node").Sub("wallet"), "address"),
address.Uint160ToString(wKey.GetScriptHash()))
}
configtest.ForEachFileType(path, fileConfigTest)
t.Run("ENV", func(t *testing.T) {
configtest.ForEnvFileType(path, fileConfigTest)
})
}