[#493] cmd/node: Implement a basic configuration component

Create `config` package nearby storage node application. Implement `Config`
as a wrapper over `viper.Viper` that provides the minimum functionality
required by the application.

The constructor allows you to read the config from the file. Methods are
provided for reading subsections and values from the config tree. Helper
functions are implemented to cast a value to native Go types.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-21 14:50:40 +03:00 committed by Leonard Lyubich
parent d34de558f0
commit 7e11bf9a55
11 changed files with 260 additions and 0 deletions

View file

@ -0,0 +1,29 @@
package config_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
"github.com/stretchr/testify/require"
)
func TestConfigCommon(t *testing.T) {
forEachFileType("test/config", func(c *config.Config) {
val := c.Value("value")
require.NotNil(t, val)
val = c.Value("non-existent value")
require.Nil(t, val)
sub := c.Sub("section")
require.NotNil(t, sub)
const nonExistentSub = "non-existent sub-section"
sub = c.Sub(nonExistentSub)
require.Nil(t, sub)
val = c.Sub(nonExistentSub).Value("value")
require.Nil(t, val)
})
}