Merge pull request #10000 from hashicorp/remove-upstream-cfg-validation

Remove zero-value validation of upstream cfg structs
This commit is contained in:
Freddy 2021-04-13 11:00:02 -06:00 committed by GitHub
commit 754be9f6a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 42 deletions

View File

@ -797,8 +797,8 @@ func (chk *PassiveHealthCheck) IsZero() bool {
} }
func (chk PassiveHealthCheck) Validate() error { func (chk PassiveHealthCheck) Validate() error {
if chk.Interval <= 0*time.Second { if chk.Interval < 0*time.Second {
return fmt.Errorf("passive health check interval must be greater than 0s") return fmt.Errorf("passive health check interval cannot be negative")
} }
return nil return nil
} }
@ -828,14 +828,14 @@ func (ul *UpstreamLimits) IsZero() bool {
} }
func (ul UpstreamLimits) Validate() error { func (ul UpstreamLimits) Validate() error {
if ul.MaxConnections != nil && *ul.MaxConnections <= 0 { if ul.MaxConnections != nil && *ul.MaxConnections < 0 {
return fmt.Errorf("max connections must be at least 0") return fmt.Errorf("max connections cannot be negative")
} }
if ul.MaxPendingRequests != nil && *ul.MaxPendingRequests <= 0 { if ul.MaxPendingRequests != nil && *ul.MaxPendingRequests < 0 {
return fmt.Errorf("max pending requests must be at least 0") return fmt.Errorf("max pending requests cannot be negative")
} }
if ul.MaxConcurrentRequests != nil && *ul.MaxConcurrentRequests <= 0 { if ul.MaxConcurrentRequests != nil && *ul.MaxConcurrentRequests < 0 {
return fmt.Errorf("max concurrent requests must be at least 0") return fmt.Errorf("max concurrent requests cannot be negative")
} }
return nil return nil
} }

View File

@ -1453,21 +1453,15 @@ func TestPassiveHealthCheck_Validate(t *testing.T) {
wantMsg string wantMsg string
}{ }{
{ {
name: "valid-interval", name: "valid interval",
input: PassiveHealthCheck{Interval: 2 * time.Second}, input: PassiveHealthCheck{Interval: 0 * time.Second},
wantErr: false, wantErr: false,
}, },
{ {
name: "negative-interval", name: "negative interval",
input: PassiveHealthCheck{Interval: -1 * time.Second}, input: PassiveHealthCheck{Interval: -1 * time.Second},
wantErr: true, wantErr: true,
wantMsg: "greater than 0s", wantMsg: "cannot be negative",
},
{
name: "zero-interval",
input: PassiveHealthCheck{Interval: 0 * time.Second},
wantErr: true,
wantMsg: "greater than 0s",
}, },
} }
@ -1492,54 +1486,36 @@ func TestUpstreamLimits_Validate(t *testing.T) {
}{ }{
{ {
name: "valid-max-conns", name: "valid-max-conns",
input: UpstreamLimits{MaxConnections: intPointer(1)},
wantErr: false,
},
{
name: "zero-max-conns",
input: UpstreamLimits{MaxConnections: intPointer(0)}, input: UpstreamLimits{MaxConnections: intPointer(0)},
wantErr: true, wantErr: false,
wantMsg: "at least 0",
}, },
{ {
name: "negative-max-conns", name: "negative-max-conns",
input: UpstreamLimits{MaxConnections: intPointer(-1)}, input: UpstreamLimits{MaxConnections: intPointer(-1)},
wantErr: true, wantErr: true,
wantMsg: "at least 0", wantMsg: "cannot be negative",
}, },
{ {
name: "valid-max-concurrent", name: "valid-max-concurrent",
input: UpstreamLimits{MaxConcurrentRequests: intPointer(1)},
wantErr: false,
},
{
name: "zero-max-concurrent",
input: UpstreamLimits{MaxConcurrentRequests: intPointer(0)}, input: UpstreamLimits{MaxConcurrentRequests: intPointer(0)},
wantErr: true, wantErr: false,
wantMsg: "at least 0",
}, },
{ {
name: "negative-max-concurrent", name: "negative-max-concurrent",
input: UpstreamLimits{MaxConcurrentRequests: intPointer(-1)}, input: UpstreamLimits{MaxConcurrentRequests: intPointer(-1)},
wantErr: true, wantErr: true,
wantMsg: "at least 0", wantMsg: "cannot be negative",
}, },
{ {
name: "valid-max-pending", name: "valid-max-pending",
input: UpstreamLimits{MaxPendingRequests: intPointer(1)},
wantErr: false,
},
{
name: "zero-max-pending",
input: UpstreamLimits{MaxPendingRequests: intPointer(0)}, input: UpstreamLimits{MaxPendingRequests: intPointer(0)},
wantErr: true, wantErr: false,
wantMsg: "at least 0",
}, },
{ {
name: "negative-max-pending", name: "negative-max-pending",
input: UpstreamLimits{MaxPendingRequests: intPointer(-1)}, input: UpstreamLimits{MaxPendingRequests: intPointer(-1)},
wantErr: true, wantErr: true,
wantMsg: "at least 0", wantMsg: "cannot be negative",
}, },
} }