Skip to content

Commit 896debc

Browse files
test(config): assert ParsePositiveDuration error branch in table
The ParsePositiveDuration table exercised all error inputs but did not distinguish which branch fired. Add an errMatch field so the table pins "must be > 0" for zero/negative and "invalid duration" for malformed/empty inputs, mirroring TestParseHelmInstallTimeoutAnnotation and keeping the two parsers' diagnostics from drifting. Address review feedback from coderabbitai on config_test.go. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 3282670 commit 896debc

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎pkg/config/config_test.go‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,23 @@ func TestParseHelmInstallTimeoutAnnotation(t *testing.T) {
124124
// HelmRelease and being rejected by helm-controller's CRD validation later.
125125
func TestParsePositiveDuration(t *testing.T) {
126126
tests := []struct {
127-
name string
128-
raw string
129-
want time.Duration
130-
wantErr bool
127+
name string
128+
raw string
129+
want time.Duration
130+
// errMatch pins which of the two error branches fired: a
131+
// time.ParseDuration failure ("invalid duration") versus a
132+
// non-positive value ("must be > 0"). Keeps the two diagnostics
133+
// from drifting and operators seeing the wrong message.
134+
errMatch string
135+
wantErr bool
131136
}{
132137
{name: "valid seconds", raw: "30s", want: 30 * time.Second},
133138
{name: "valid minutes", raw: "5m", want: 5 * time.Minute},
134139
{name: "valid compound", raw: "1h30m", want: 90 * time.Minute},
135-
{name: "zero rejected", raw: "0s", wantErr: true},
136-
{name: "negative rejected", raw: "-5m", wantErr: true},
137-
{name: "malformed rejected", raw: "5x", wantErr: true},
138-
{name: "empty rejected", raw: "", wantErr: true},
140+
{name: "zero rejected", raw: "0s", wantErr: true, errMatch: "must be > 0"},
141+
{name: "negative rejected", raw: "-5m", wantErr: true, errMatch: "must be > 0"},
142+
{name: "malformed rejected", raw: "5x", wantErr: true, errMatch: "invalid duration"},
143+
{name: "empty rejected", raw: "", wantErr: true, errMatch: "invalid duration"},
139144
}
140145

141146
for _, tt := range tests {
@@ -145,6 +150,9 @@ func TestParsePositiveDuration(t *testing.T) {
145150
if err == nil {
146151
t.Fatalf("expected error for %q, got nil", tt.raw)
147152
}
153+
if tt.errMatch != "" && !strings.Contains(err.Error(), tt.errMatch) {
154+
t.Errorf("error %q does not contain %q", err.Error(), tt.errMatch)
155+
}
148156
return
149157
}
150158
if err != nil {

0 commit comments

Comments
 (0)