Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Aug 22, 2024
1 parent 0c5f1b5 commit cfa6a09
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/checks/promql_rate_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package checks_test

import (
"errors"
"fmt"
"testing"
"time"

v1 "github.com/prometheus/client_golang/api/prometheus/v1"

"github.com/cloudflare/pint/internal/checks"
"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"
"github.com/cloudflare/pint/internal/promapi"
)
Expand Down Expand Up @@ -787,6 +789,56 @@ func TestRateCheck(t *testing.T) {
},
},
},
{
description: "sum_over_rate / ignore entry with PathError",
content: "- alert: my alert\n expr: rate(my:sum[5m])\n",
entries: []discovery.Entry{{PathError: errors.New("mock error")}},
checker: newRateCheck,
prometheus: newSimpleProm,
problems: noProblems,
mocks: []*prometheusMock{
{
conds: []requestCondition{requireConfigPath},
resp: configResponse{yaml: "global:\n scrape_interval: 1m\n"},
},
{
conds: []requestCondition{
requireMetadataPath,
formCond{"metric", "my:sum"},
},
resp: metadataResponse{metadata: map[string][]v1.Metadata{}},
},
},
},
{
description: "sum_over_rate / ignore entry with rule error",
content: "- alert: my alert\n expr: rate(my:sum[5m])\n",
entries: []discovery.Entry{
{
Rule: parser.Rule{
Error: parser.ParseError{
Err: errors.New("mock error"),
},
},
},
},
checker: newRateCheck,
prometheus: newSimpleProm,
problems: noProblems,
mocks: []*prometheusMock{
{
conds: []requestCondition{requireConfigPath},
resp: configResponse{yaml: "global:\n scrape_interval: 1m\n"},
},
{
conds: []requestCondition{
requireMetadataPath,
formCond{"metric", "my:sum"},
},
resp: metadataResponse{metadata: map[string][]v1.Metadata{}},
},
},
},
}
runTests(t, testCases)
}

0 comments on commit cfa6a09

Please sign in to comment.