From 24289e23b8ad499ee3bfd0dfededf4e5f4b8b252 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Tue, 15 Jun 2021 09:38:35 +0200 Subject: [PATCH] Specify the value has to be greater than 0 Signed-off-by: Francesco Guardiani --- pkg/apis/duck/v1/delivery_types.go | 6 +++--- pkg/apis/duck/v1/delivery_types_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/apis/duck/v1/delivery_types.go b/pkg/apis/duck/v1/delivery_types.go index 6857a73978c..b82bbc4f9b7 100644 --- a/pkg/apis/duck/v1/delivery_types.go +++ b/pkg/apis/duck/v1/delivery_types.go @@ -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 @@ -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 { diff --git a/pkg/apis/duck/v1/delivery_types_test.go b/pkg/apis/duck/v1/delivery_types_test.go index cb4860ee88a..ca82ed2b15b 100644 --- a/pkg/apis/duck/v1/delivery_types_test.go +++ b/pkg/apis/duck/v1/delivery_types_test.go @@ -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},