Skip to content

Commit

Permalink
feat: PC-13831 unique SLOs validation and test (#526)
Browse files Browse the repository at this point in the history
## Release Notes

Added BudgetAdjustment validation for unique SLOs in filters
  • Loading branch information
jakubpieta authored Aug 22, 2024
1 parent f2f7faf commit b988a29
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion manifest/v1alpha/budgetadjustment/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ var filtersValidationRule = validation.New(
validation.ForSlice(func(f Filters) []SLORef { return f.SLOs }).
WithName("slos").
Rules(validation.SliceMinLength[[]SLORef](1)).
IncludeForEach(sloValidationRule),
IncludeForEach(sloValidationRule).
Rules(validation.SliceUnique(func(s SLORef) string {
return s.Project + s.Name
}, "SLOs must be unique")),
)

var sloValidationRule = validation.New(
Expand Down
45 changes: 45 additions & 0 deletions manifest/v1alpha/budgetadjustment/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,51 @@ func TestValidate_Spec(t *testing.T) {
},
},
},
{
name: "duplicate slo",
spec: Spec{
FirstEventStart: time.Now(),
Duration: "1m",
Rrule: "FREQ=WEEKLY;INTERVAL=2",
Filters: Filters{
SLOs: []SLORef{
{Name: "test", Project: "project"},
{Name: "test", Project: "project"},
},
},
},
expectedErrors: []testutils.ExpectedError{
{
Prop: "spec.filters.slos",
Code: validation.ErrorCodeSliceUnique,
},
},
},
{
name: "duplicate slo with multiple others",
spec: Spec{
FirstEventStart: time.Now(),
Duration: "1m",
Rrule: "FREQ=WEEKLY;INTERVAL=2",
Filters: Filters{
SLOs: []SLORef{
{Name: "test1", Project: "project"},
{Name: "test1", Project: "project"},
{Name: "test2", Project: "project"},
{Name: "test3", Project: "project"},
{Name: "test4", Project: "project"},
{Name: "test5", Project: "project"},
{Name: "test6", Project: "project"},
},
},
},
expectedErrors: []testutils.ExpectedError{
{
Prop: "spec.filters.slos",
Code: validation.ErrorCodeSliceUnique,
},
},
},
{
name: "proper spec",
spec: Spec{
Expand Down

0 comments on commit b988a29

Please sign in to comment.