From b8a5f09174351f11719e7c88a993d3e61fde032a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 21 May 2021 16:46:15 +0300 Subject: [PATCH] [#493] node/config: Export useful functions into a separate test package Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config/calls_test.go | 3 ++- cmd/neofs-node/config/cast_test.go | 5 ++-- cmd/neofs-node/config/config_test.go | 26 --------------------- cmd/neofs-node/config/test/config.go | 34 ++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 29 deletions(-) delete mode 100644 cmd/neofs-node/config/config_test.go create mode 100644 cmd/neofs-node/config/test/config.go diff --git a/cmd/neofs-node/config/calls_test.go b/cmd/neofs-node/config/calls_test.go index b66eea7c3..61d91250a 100644 --- a/cmd/neofs-node/config/calls_test.go +++ b/cmd/neofs-node/config/calls_test.go @@ -4,11 +4,12 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" "github.com/stretchr/testify/require" ) func TestConfigCommon(t *testing.T) { - forEachFileType("test/config", func(c *config.Config) { + configtest.ForEachFileType("test/config", func(c *config.Config) { val := c.Value("value") require.NotNil(t, val) diff --git a/cmd/neofs-node/config/cast_test.go b/cmd/neofs-node/config/cast_test.go index 9d7b96cd2..a2bb2f19e 100644 --- a/cmd/neofs-node/config/cast_test.go +++ b/cmd/neofs-node/config/cast_test.go @@ -4,11 +4,12 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" "github.com/stretchr/testify/require" ) func TestStringSlice(t *testing.T) { - forEachFileType("test/config", func(c *config.Config) { + configtest.ForEachFileType("test/config", func(c *config.Config) { cStringSlice := c.Sub("string_slice") val := config.StringSlice(cStringSlice, "empty") @@ -30,7 +31,7 @@ func TestStringSlice(t *testing.T) { } func TestString(t *testing.T) { - forEachFileType("test/config", func(c *config.Config) { + configtest.ForEachFileType("test/config", func(c *config.Config) { c = c.Sub("string") val := config.String(c, "correct") diff --git a/cmd/neofs-node/config/config_test.go b/cmd/neofs-node/config/config_test.go deleted file mode 100644 index 231f59b2f..000000000 --- a/cmd/neofs-node/config/config_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package config_test - -import ( - "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" -) - -func fromFile(path string) *config.Config { - var p config.Prm - - return config.New(p, - config.WithConfigFile(path), - ) -} - -func forEachFile(paths []string, f func(*config.Config)) { - for i := range paths { - f(fromFile(paths[i])) - } -} - -func forEachFileType(pref string, f func(*config.Config)) { - forEachFile([]string{ - pref + ".yaml", - pref + ".json", - }, f) -} diff --git a/cmd/neofs-node/config/test/config.go b/cmd/neofs-node/config/test/config.go new file mode 100644 index 000000000..a1b98ef8d --- /dev/null +++ b/cmd/neofs-node/config/test/config.go @@ -0,0 +1,34 @@ +package configtest + +import "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + +func fromFile(path string) *config.Config { + var p config.Prm + + return config.New(p, + config.WithConfigFile(path), + ) +} + +func forEachFile(paths []string, f func(*config.Config)) { + for i := range paths { + f(fromFile(paths[i])) + } +} + +// ForEachFileType passes configs read from next files: +// - `.yaml`; +// - `.json`. +func ForEachFileType(pref string, f func(*config.Config)) { + forEachFile([]string{ + pref + ".yaml", + pref + ".json", + }, f) +} + +// EmptyConfig returns config without any values and sections. +func EmptyConfig() *config.Config { + var p config.Prm + + return config.New(p) +}