[#493] node/config: Export useful functions into a separate test package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-21 16:46:15 +03:00 committed by Leonard Lyubich
parent c645781b98
commit b8a5f09174
4 changed files with 39 additions and 29 deletions

View file

@ -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:
// - `<pref>.yaml`;
// - `<pref>.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)
}