From e61aec4a7ddda2443a98657ff1b7bb705d2b2914 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 25 Apr 2023 08:55:42 +0300 Subject: [PATCH] [#125] node: Remove unused config.Prm Signed-off-by: Anton Nikiforov --- cmd/frostfs-node/config/config.go | 5 +---- cmd/frostfs-node/config/configdir_test.go | 2 +- cmd/frostfs-node/config/test/config.go | 12 +++--------- cmd/frostfs-node/main.go | 2 +- cmd/frostfs-node/validate_test.go | 4 ++-- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/cmd/frostfs-node/config/config.go b/cmd/frostfs-node/config/config.go index e1b142aed..383897fc8 100644 --- a/cmd/frostfs-node/config/config.go +++ b/cmd/frostfs-node/config/config.go @@ -26,15 +26,12 @@ const ( EnvPrefix = "FROSTFS" ) -// Prm groups required parameters of the Config. -type Prm struct{} - // New creates a new Config instance. // // If file option is provided (WithConfigFile), // configuration values are read from it. // Otherwise, Config is a degenerate tree. -func New(_ Prm, opts ...configViper.Option) *Config { +func New(opts ...configViper.Option) *Config { v, o, err := configViper.CreateViper(opts...) if err != nil { diff --git a/cmd/frostfs-node/config/configdir_test.go b/cmd/frostfs-node/config/configdir_test.go index 2e2e831a1..f41e6edd9 100644 --- a/cmd/frostfs-node/config/configdir_test.go +++ b/cmd/frostfs-node/config/configdir_test.go @@ -19,7 +19,7 @@ func TestConfigDir(t *testing.T) { require.NoError(t, os.WriteFile(cfgFileName0, []byte(`{"storage":{"shard_pool_size":15}}`), 0777)) require.NoError(t, os.WriteFile(cfgFileName1, []byte("logger:\n level: debug"), 0777)) - c := New(Prm{}, configViper.WithConfigDir(dir)) + c := New(configViper.WithConfigDir(dir)) require.Equal(t, "debug", cast.ToString(c.Sub("logger").Value("level"))) require.EqualValues(t, 15, cast.ToUint32(c.Sub("storage").Value("shard_pool_size"))) } diff --git a/cmd/frostfs-node/config/test/config.go b/cmd/frostfs-node/config/test/config.go index b3f659030..2bd5ade21 100644 --- a/cmd/frostfs-node/config/test/config.go +++ b/cmd/frostfs-node/config/test/config.go @@ -12,21 +12,17 @@ import ( ) func fromFile(path string) *config.Config { - var p config.Prm - os.Clearenv() // ENVs have priority over config files, so we do this in tests - return config.New(p, + return config.New( configViper.WithConfigFile(path), ) } func fromEnvFile(t testing.TB, path string) *config.Config { - var p config.Prm - loadEnv(t, path) // github.com/joho/godotenv can do that as well - return config.New(p, configViper.WithEnvPrefix(config.EnvPrefix)) + return config.New(configViper.WithEnvPrefix(config.EnvPrefix)) } func forEachFile(paths []string, f func(*config.Config)) { @@ -52,9 +48,7 @@ func ForEnvFileType(t testing.TB, pref string, f func(*config.Config)) { // EmptyConfig returns config without any values and sections. func EmptyConfig() *config.Config { - var p config.Prm - - return config.New(p, configViper.WithEnvPrefix(config.EnvPrefix)) + return config.New(configViper.WithEnvPrefix(config.EnvPrefix)) } // loadEnv reads .env file, parses `X=Y` records and sets OS ENVs. diff --git a/cmd/frostfs-node/main.go b/cmd/frostfs-node/main.go index 877a80f6a..5a66b210b 100644 --- a/cmd/frostfs-node/main.go +++ b/cmd/frostfs-node/main.go @@ -47,7 +47,7 @@ func main() { os.Exit(SuccessReturnCode) } - appCfg := config.New(config.Prm{}, + appCfg := config.New( configViper.WithConfigFile(*configFile), configViper.WithConfigDir(*configDir), configViper.WithEnvPrefix(config.EnvPrefix)) diff --git a/cmd/frostfs-node/validate_test.go b/cmd/frostfs-node/validate_test.go index 74903884b..75b694cec 100644 --- a/cmd/frostfs-node/validate_test.go +++ b/cmd/frostfs-node/validate_test.go @@ -27,13 +27,13 @@ func TestValidate(t *testing.T) { t.Run("mainnet", func(t *testing.T) { os.Clearenv() // ENVs have priority over config files, so we do this in tests p := filepath.Join(exampleConfigPrefix, "mainnet/config.yml") - c := config.New(config.Prm{}, configViper.WithConfigFile(p)) + c := config.New(configViper.WithConfigFile(p)) require.NoError(t, validateConfig(c)) }) t.Run("testnet", func(t *testing.T) { os.Clearenv() // ENVs have priority over config files, so we do this in tests p := filepath.Join(exampleConfigPrefix, "testnet/config.yml") - c := config.New(config.Prm{}, configViper.WithConfigFile(p)) + c := config.New(configViper.WithConfigFile(p)) require.NoError(t, validateConfig(c)) }) }