Skip to content

Commit

Permalink
fix lint issuesAllow Config.Explain on empty Config (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored Jul 8, 2024
1 parent b149c9a commit d34da87
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.2.2] - 2024-07-08

### Fixed

- Allow Config.Explain on empty Config (#408).

## [1.2.1] - 2024-06-20

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (c *Config) transformKeys(m map[string]any) {
// from loaders for the given path. It blur sensitive information.
// The path is case-insensitive unless konf.WithCaseSensitive is set.
func (c *Config) Explain(path string) string {
if c == nil {
if c == nil || c.values.Load() == nil {
return path + " has no configuration.\n\n"
}

Expand Down
8 changes: 8 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func TestConfig_nil(t *testing.T) {
var value string
assert.NoError(t, config.Unmarshal("key", &value))
assert.Equal(t, "", value)
assert.True(t, len(config.Explain("key")) > 0)

config = konf.New()
assert.True(t, !config.Exists([]string{"key"}))
assert.Equal(t, "key has no configuration.\n\n", config.Explain("key"))
assert.NoError(t, config.Unmarshal("key", &value))
assert.Equal(t, "", value)
assert.True(t, len(config.Explain("key")) > 0)
}

func TestConfig_Load(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Statuser interface {
//
// It's used by the loader to check if the configuration has been set by other loaders.
func (c *Config) Exists(path []string) bool {
if c == nil {
if c == nil || c.values.Load() == nil {
return false
}

Expand Down

0 comments on commit d34da87

Please sign in to comment.