diff --git a/v2/dtos/requests/subscription_test.go b/v2/dtos/requests/subscription_test.go index 37d8a96f..1e94896d 100644 --- a/v2/dtos/requests/subscription_test.go +++ b/v2/dtos/requests/subscription_test.go @@ -211,6 +211,10 @@ func TestUpdateSubscriptionRequest_Validate(t *testing.T) { unsupportedChannelType.Subscription.Channels = []dtos.Address{ dtos.NewMQTTAddress("host", 123, "publisher", "topic"), } + validWithoutChannels := NewUpdateSubscriptionRequest(updateSubscriptionData()) + validWithoutChannels.Subscription.Channels = nil + invalidEmptyChannels := NewUpdateSubscriptionRequest(updateSubscriptionData()) + invalidEmptyChannels.Subscription.Channels = []dtos.Address{} categoryNameWithReservedChar := NewUpdateSubscriptionRequest(updateSubscriptionData()) categoryNameWithReservedChar.Subscription.Categories = []string{namesWithReservedChar[0]} @@ -239,6 +243,8 @@ func TestUpdateSubscriptionRequest_Validate(t *testing.T) { {"invalid, category name containing reserved chars", categoryNameWithReservedChar, true}, {"invalid, receiver name containing reserved chars", receiverNameWithReservedChars, true}, {"invalid, resendInterval is not specified in ISO8601 format", invalidResendInterval, true}, + {"valid, without channels", validWithoutChannels, false}, + {"invalid, empty channels", invalidEmptyChannels, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/v2/dtos/subscription.go b/v2/dtos/subscription.go index 26e4ab7d..b611887c 100644 --- a/v2/dtos/subscription.go +++ b/v2/dtos/subscription.go @@ -29,7 +29,7 @@ type Subscription struct { type UpdateSubscription struct { Id *string `json:"id,omitempty" validate:"required_without=Name,edgex-dto-uuid"` Name *string `json:"name,omitempty" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` - Channels []Address `json:"channels,omitempty" validate:"omitempty,dive"` + Channels []Address `json:"channels,omitempty" validate:"omitempty,gt=0,dive"` Receiver *string `json:"receiver,omitempty" validate:"omitempty,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` Categories []string `json:"categories,omitempty" validate:"omitempty,dive,gt=0,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` Labels []string `json:"labels,omitempty" validate:"omitempty,dive,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`