signoz/pkg/query-service/rules/base_rule_test.go
Vikrant Gupta 16e0fa2eef
feat(ruler): update the ruler and planned maintenance tables (#7535)
* feat(ruler): base setup for rules and planned maintenance tables

* feat(ruler): more changes for making ruler org aware

* feat(ruler): fix lint

* feat(ruler): update the edit planned maintenance function

* feat(ruler): local testing edits for planned maintenance

* feat(ruler): abstract store and types from rules pkg

* feat(ruler): abstract store and types from rules pkg

* feat(ruler): abstract out store and add migration

* feat(ruler): frontend changes and review comments

* feat(ruler): add back compareAndSelectConfig

* feat(ruler): changes for alertmanager matchers

* feat(ruler): addressed review comments

* feat(ruler): remove the cascade operations from rules table

* feat(ruler): update the template for alertmanager

* feat(ruler): implement the rule history changes

* feat(ruler): implement the rule history changes

* feat(ruler): implement the rule history changes

---------

Co-authored-by: Vibhu Pandey <vibhupandey28@gmail.com>
2025-04-18 00:04:25 +05:30

66 lines
1.4 KiB
Go

package rules
import (
"testing"
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
ruletypes "github.com/SigNoz/signoz/pkg/types/ruletypes"
)
func TestBaseRule_RequireMinPoints(t *testing.T) {
threshold := 1.0
tests := []struct {
name string
rule *BaseRule
shouldAlert bool
series *v3.Series
}{
{
name: "test should skip if less than min points",
rule: &BaseRule{
ruleCondition: &ruletypes.RuleCondition{
RequireMinPoints: true,
RequiredNumPoints: 4,
},
},
series: &v3.Series{
Points: []v3.Point{
{Value: 1},
{Value: 2},
},
},
shouldAlert: false,
},
{
name: "test should alert if more than min points",
rule: &BaseRule{
ruleCondition: &ruletypes.RuleCondition{
RequireMinPoints: true,
RequiredNumPoints: 4,
CompareOp: ruletypes.ValueIsAbove,
MatchType: ruletypes.AtleastOnce,
Target: &threshold,
},
},
series: &v3.Series{
Points: []v3.Point{
{Value: 1},
{Value: 2},
{Value: 3},
{Value: 4},
},
},
shouldAlert: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, shouldAlert := test.rule.ShouldAlert(*test.series)
if shouldAlert != test.shouldAlert {
t.Errorf("expected shouldAlert to be %v, got %v", test.shouldAlert, shouldAlert)
}
})
}
}