Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions configcheck/configcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func (c *Collector) Errorf(format string, args ...any) {
c.append(Finding{Path: c.path, Message: fmt.Sprintf(format, args...)})
}

// Inert adds a finding at c's path for each of names: a setting that is
// populated but has no effect in this configuration. A setting that silently
// does nothing leaves an operator believing it applies, so a command rejects
// it rather than warning. Each name may carry a short reason in parentheses.
// No names adds nothing.
func (c *Collector) Inert(names ...string) {
for _, name := range names {
c.Errorf("%s is set but has no effect, remove it", name)
}
}

// Add adds err to c. An *Error, such as one returned by Decode, contributes
// each of its findings with c's path prefixed; any other error becomes one
// finding at c's path. A nil err adds nothing.
Expand Down
15 changes: 15 additions & 0 deletions configcheck/configcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ func TestCollector_AddTurnsAPlainErrorIntoOneFinding(t *testing.T) {
}, c.Findings())
}

func TestCollector_InertReportsEachSettingAtThePath(t *testing.T) {
t.Parallel()

c := configcheck.NewCollector()
c.Inert()
assert.NoError(t, c.Err(), "no names adds nothing")

c.Field("management").Inert("allow-non-loopback (only applies with a listener)", "debug")

assert.Equal(t, []configcheck.Finding{
{Path: "management", Message: "allow-non-loopback (only applies with a listener) is set but has no effect, remove it"},
{Path: "management", Message: "debug is set but has no effect, remove it"},
}, c.Findings())
}

func TestCollector_ErrIsNilWithoutFindings(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dioad/config

go 1.25.0
go 1.26.0

require (
github.com/dioad/util v0.7.0
Expand All @@ -12,8 +12,8 @@ require (
github.com/dioad/generics v0.0.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
github.com/rogpeppe/go-internal v1.16.0 // indirect
go.yaml.in/yaml/v3 v3.0.6 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
go.yaml.in/yaml/v3 v3.0.6 h1:zcDfvjXEqTQmpjniUBLc91xYJMB2c4QOFxEF/LCEckM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
Loading