From f573c41946ade417c31efb9c3c5f9e3835f78c7f Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:42:08 +0200 Subject: [PATCH] feat: add ut --- config/config.go | 11 +++++------ config/config_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 config/config_test.go diff --git a/config/config.go b/config/config.go index c6d4c641..192c3b10 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "bytes" "errors" - "fmt" "path/filepath" "strings" @@ -168,16 +167,18 @@ func Default() (*Config, error) { return &cfg, nil } +func Load(ctx *cli.Context) (*Config, error) { + configFilePath := ctx.String(FlagCfg) + return LoadFile(configFilePath) +} // Load loads the configuration -func Load(ctx *cli.Context) (*Config, error) { +func LoadFile(configFilePath string) (*Config, error) { cfg, err := Default() if err != nil { return nil, err } expectedKeys := viper.AllKeys() - - configFilePath := ctx.String(FlagCfg) if configFilePath != "" { dirName, fileName := filepath.Split(configFilePath) @@ -231,8 +232,6 @@ func Load(ctx *cli.Context) (*Config, error) { } } } - fmt.Println("cfg", cfg.NetworkConfig.L1Config) - return cfg, nil } diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 00000000..98003598 --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,18 @@ +package config + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestXxx(t *testing.T) { + tmpFile, err := os.CreateTemp("", "ut_config") + require.NoError(t, err) + defer os.Remove(tmpFile.Name()) + tmpFile.Write([]byte(DefaultValues)) + cfg, err := LoadFile(tmpFile.Name()) + require.NoError(t, err) + require.NotNil(t, cfg) +}