Skip to content

Commit

Permalink
Specify the value has to be greater than 0
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper committed Jun 15, 2021
1 parent 5360550 commit 24289e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/apis/duck/v1/delivery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type DeliverySpec struct {
// +optional
Retry *int32 `json:"retry,omitempty"`

// Timeout is the timeout of each single request.
// Timeout is the timeout of each single request. The value must be greater than 0.
// More information on Duration format:
// - https://www.iso.org/iso-8601-date-and-time-format.html
// - https://en.wikipedia.org/wiki/ISO_8601
Expand Down Expand Up @@ -77,8 +77,8 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {

if ds.Timeout != nil {
if feature.FromContext(ctx).IsEnabled(feature.DeliveryTimeout) {
_, te := period.Parse(*ds.Timeout)
if te != nil {
t, te := period.Parse(*ds.Timeout)
if te != nil || t.IsZero() {
errs = errs.Also(apis.ErrInvalidValue(*ds.Timeout, "timeout"))
}
} else {
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/duck/v1/delivery_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func TestDeliverySpecValidation(t *testing.T) {
want: func() *apis.FieldError {
return apis.ErrInvalidValue(invalidDuration, "timeout")
}(),
}, {
name: "zero timeout",
spec: &DeliverySpec{Timeout: pointer.StringPtr("PT0S")},
ctx: deliveryTimeoutEnabledCtx,
want: func() *apis.FieldError {
return apis.ErrInvalidValue("PT0S", "timeout")
}(),
}, {
name: "disabled timeout",
spec: &DeliverySpec{Timeout: &validDuration},
Expand Down

0 comments on commit 24289e2

Please sign in to comment.