Skip to content

Commit

Permalink
feat: add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 18, 2024
1 parent 9ab6491 commit f573c41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 5 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"bytes"
"errors"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -231,8 +232,6 @@ func Load(ctx *cli.Context) (*Config, error) {
}
}
}
fmt.Println("cfg", cfg.NetworkConfig.L1Config)

return cfg, nil
}

Expand Down
18 changes: 18 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -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))

Check failure on line 14 in config/config_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `tmpFile.Write` is not checked (errcheck)
cfg, err := LoadFile(tmpFile.Name())
require.NoError(t, err)
require.NotNil(t, cfg)
}

0 comments on commit f573c41

Please sign in to comment.