Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
This commit is contained in:
Neeraj Gartia 2025-02-24 20:29:11 +05:30
parent 853d5ada2a
commit 389c818ace
2 changed files with 4 additions and 5 deletions

View file

@ -266,7 +266,7 @@ func parseSeries(defLine string, line int) (labels.Labels, []parser.SequenceValu
return metric, vals, nil
}
func parseExpect(defLine string, i int) (expectCmdType, expectCmd, error) {
func parseExpect(defLine string) (expectCmdType, expectCmd, error) {
expectParts := patExpect.FindStringSubmatch(strings.TrimSpace(defLine))
expCmd := expectCmd{}
if expectParts == nil {
@ -415,7 +415,7 @@ func (t *test) parseEval(lines []string, i int) (int, *evalCmd, error) {
// This would still allow a metric named 'expect' if it is written as 'expect{}'.
if strings.Split(defLine, " ")[0] == "expect" {
annoType, expectedAnno, err := parseExpect(defLine, i)
annoType, expectedAnno, err := parseExpect(defLine)
if err != nil {
return i, nil, formatErr("%w", err)
}
@ -804,9 +804,7 @@ func validateExpectedAnnotations(expr string, expectedAnnotations []expectCmd, a
// Check if all expected annotations are found in actual.
for _, e := range expectedAnnotations {
matchFound := slices.ContainsFunc(actualAnnotations, func(anno string) bool {
return e.CheckMatch(anno)
})
matchFound := slices.ContainsFunc(actualAnnotations, e.CheckMatch)
if !matchFound {
return fmt.Errorf("expected %s annotation %q but no matching annotation was found for query %q (line %d)", annotationType, e.String(), expr, line)
}

View file

@ -374,6 +374,7 @@ eval_info instant at 50m sort(rate(http_requests[10m]))
"instant query with unexpected info annotation": {
input: testData + `
eval instant at 50m sort(rate(http_requests[10m]))
expect no_info
{group="production", instance="0", job="api-server"} 0.03333333333333333
{group="production", instance="1", job="api-server"} 0.06666666666666667
{group="canary", instance="0", job="api-server"} 0.1