Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/apis/sources/v1/ping_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"

Expand All @@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError {

func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError

schedule := cs.Schedule

errs = validateDescriptor(schedule)

if cs.Timezone != "" {
schedule = "CRON_TZ=" + cs.Timezone + " " + schedule
}
Expand Down Expand Up @@ -98,3 +101,10 @@ func validateJSON(str string) error {
var objmap map[string]interface{}
return json.Unmarshal([]byte(str), &objmap)
}

func validateDescriptor(spec string) *apis.FieldError {
if strings.Contains(spec, "@every") {
return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule")
}
return nil
}
45 changes: 45 additions & 0 deletions pkg/apis/sources/v1/ping_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,51 @@ func TestPingSourceValidation(t *testing.T) {
},
},
want: nil,
}, {
name: "unsupported @every descriptor",
source: PingSource{
Spec: PingSourceSpec{
Schedule: "@every 2h",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
Ref: &duckv1.KReference{
APIVersion: "v1",
Kind: "broker",
Name: "default",
},
},
},
},
},
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrInvalidValue("unsupported descriptor @every", "spec.schedule")
errs = errs.Also(fe)
return errs
}(),
}, {
name: "unsupported @every descriptor with TZ",
source: PingSource{
Spec: PingSourceSpec{
Schedule: "@every 2h",
Timezone: "Europe/Paris",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
Ref: &duckv1.KReference{
APIVersion: "v1",
Kind: "broker",
Name: "default",
},
},
},
},
},
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrInvalidValue("unsupported descriptor @every", "spec.schedule")
errs = errs.Also(fe)
return errs
}(),
},
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/apis/sources/v1beta2/ping_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"

Expand All @@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError {

func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError

schedule := cs.Schedule

errs = validateDescriptor(schedule)

if cs.Timezone != "" {
schedule = "CRON_TZ=" + cs.Timezone + " " + schedule
}
Expand Down Expand Up @@ -98,3 +101,10 @@ func validateJSON(str string) error {
var objmap map[string]interface{}
return json.Unmarshal([]byte(str), &objmap)
}

func validateDescriptor(spec string) *apis.FieldError {
if strings.Contains(spec, "@every") {
return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule")
}
return nil
}
45 changes: 45 additions & 0 deletions pkg/apis/sources/v1beta2/ping_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,51 @@ func TestPingSourceValidation(t *testing.T) {
},
},
want: nil,
}, {
name: "unsupported @every descriptor",
source: PingSource{
Spec: PingSourceSpec{
Schedule: "@every 2h",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
Ref: &duckv1.KReference{
APIVersion: "v1",
Kind: "broker",
Name: "default",
},
},
},
},
},
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrInvalidValue("unsupported descriptor @every", "spec.schedule")
errs = errs.Also(fe)
return errs
}(),
}, {
name: "unsupported @every descriptor with TZ",
source: PingSource{
Spec: PingSourceSpec{
Schedule: "@every 2h",
Timezone: "Europe/Paris",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
Ref: &duckv1.KReference{
APIVersion: "v1",
Kind: "broker",
Name: "default",
},
},
},
},
},
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrInvalidValue("unsupported descriptor @every", "spec.schedule")
errs = errs.Also(fe)
return errs
}(),
},
}

Expand Down