Skip to content

Commit

Permalink
Merge branch 'main' into PC-15330-thousandeyes-api-test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinlawnik authored Jan 21, 2025
2 parents 9def9fd + bf8b69b commit 691cb07
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
34 changes: 18 additions & 16 deletions manifest/v1alpha/report/validation_slo_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ import (
)

var sloHistoryValidation = govy.New[SLOHistoryConfig](
govy.For(func(s SLOHistoryConfig) string { return s.TimeFrame.TimeZone }).
WithName("timeZone").
Required().
Rules(govy.NewRule(func(v string) error {
if _, err := time.LoadLocation(v); err != nil {
return errors.Wrap(err, "not a valid time zone")
}
return nil
})),
govy.For(func(s SLOHistoryConfig) SLOHistoryTimeFrame { return s.TimeFrame }).
WithName("timeFrame").
Required().
Rules(rules.MutuallyExclusive(true, map[string]func(t SLOHistoryTimeFrame) any{
"rolling": func(t SLOHistoryTimeFrame) any { return t.Rolling },
"calendar": func(t SLOHistoryTimeFrame) any { return t.Calendar },
})),
govy.ForPointer(func(s SLOHistoryConfig) *RollingTimeFrame { return s.TimeFrame.Rolling }).
WithName("rolling").
Include(rollingTimeFrameValidation),
govy.ForPointer(func(s SLOHistoryConfig) *CalendarTimeFrame { return s.TimeFrame.Calendar }).
WithName("calendar").
Include(calendarTimeFrameValidation),
})).
Include(govy.New[SLOHistoryTimeFrame](
govy.For(func(s SLOHistoryTimeFrame) string { return s.TimeZone }).
WithName("timeZone").
Required().
Rules(govy.NewRule(func(v string) error {
if _, err := time.LoadLocation(v); err != nil {
return errors.Wrap(err, "not a valid time zone")
}
return nil
})),
govy.ForPointer(func(s SLOHistoryTimeFrame) *RollingTimeFrame { return s.Rolling }).
WithName("rolling").
Include(rollingTimeFrameValidation),
govy.ForPointer(func(s SLOHistoryTimeFrame) *CalendarTimeFrame { return s.Calendar }).
WithName("calendar").
Include(calendarTimeFrameValidation),
)),
)
36 changes: 18 additions & 18 deletions manifest/v1alpha/report/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 3,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.rolling.unit",
Prop: "spec.sloHistory.timeFrame.rolling.unit",
Code: rules.ErrorCodeRequired,
},
{
Prop: "spec.sloHistory.rolling.count",
Prop: "spec.sloHistory.timeFrame.rolling.count",
Code: rules.ErrorCodeRequired,
},
{
Prop: "spec.sloHistory.rolling",
Prop: "spec.sloHistory.timeFrame.rolling",
Message: validUnitAndCountRollingPairs,
},
},
Expand All @@ -406,11 +406,11 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 2,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.rolling.count",
Prop: "spec.sloHistory.timeFrame.rolling.count",
Code: rules.ErrorCodeRequired,
},
{
Prop: "spec.sloHistory.rolling",
Prop: "spec.sloHistory.timeFrame.rolling",
Message: validUnitAndCountRollingPairs,
},
},
Expand All @@ -427,11 +427,11 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 2,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.rolling.unit",
Prop: "spec.sloHistory.timeFrame.rolling.unit",
Code: rules.ErrorCodeRequired,
},
{
Prop: "spec.sloHistory.rolling",
Prop: "spec.sloHistory.timeFrame.rolling",
Message: validUnitAndCountRollingPairs,
},
},
Expand All @@ -448,11 +448,11 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 2,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.rolling.unit",
Prop: "spec.sloHistory.timeFrame.rolling.unit",
Code: rules.ErrorCodeOneOf,
},
{
Prop: "spec.sloHistory.rolling",
Prop: "spec.sloHistory.timeFrame.rolling",
Message: validUnitAndCountRollingPairs,
},
},
Expand All @@ -470,7 +470,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.rolling",
Prop: "spec.sloHistory.timeFrame.rolling",
Message: validUnitAndCountRollingPairs,
},
},
Expand All @@ -488,7 +488,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.timeZone",
Prop: "spec.sloHistory.timeFrame.timeZone",
Code: rules.ErrorCodeRequired,
},
},
Expand All @@ -505,7 +505,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.timeZone",
Prop: "spec.sloHistory.timeFrame.timeZone",
Message: "not a valid time zone: unknown time zone x",
},
},
Expand All @@ -523,7 +523,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.calendar",
Prop: "spec.sloHistory.timeFrame.calendar",
Message: validCalendarPairs,
},
},
Expand All @@ -536,7 +536,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.calendar",
Prop: "spec.sloHistory.timeFrame.calendar",
Message: validCalendarPairs,
},
},
Expand All @@ -553,11 +553,11 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 2,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.calendar.unit",
Prop: "spec.sloHistory.timeFrame.calendar.unit",
Code: rules.ErrorCodeOneOf,
},
{
Prop: "spec.sloHistory.calendar",
Prop: "spec.sloHistory.timeFrame.calendar",
Message: validUnitAndCountCalendarPairs,
},
},
Expand All @@ -575,7 +575,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.calendar",
Prop: "spec.sloHistory.timeFrame.calendar",
Message: validUnitAndCountCalendarPairs,
},
},
Expand All @@ -593,7 +593,7 @@ func TestValidate_Spec_SLOHistory_TimeFrame(t *testing.T) {
ExpectedErrorsCount: 1,
ExpectedErrors: []testutils.ExpectedError{
{
Prop: "spec.sloHistory.calendar",
Prop: "spec.sloHistory.timeFrame.calendar",
Message: "dates must be in the past",
},
},
Expand Down

0 comments on commit 691cb07

Please sign in to comment.