Skip to content

Commit

Permalink
Merge pull request #911 from cloudflare/tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
prymitive authored Mar 14, 2024
2 parents eb933aa + 49a19b8 commit 9e508e9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Fetch test rules
run: make -C cmd/pint/bench fetch
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:
jobs:
ci:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == 'cloudflare/pint' }}
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -29,6 +30,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Compile pint
run: make build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Build binary
run: make
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/go-mod-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Run go mod tidy
run: go mod tidy
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Test
run: make test
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c AlertsCheck) Check(ctx context.Context, _ string, rule parser.Rule, _ []
Lines: rule.AlertingRule.Expr.Value.Lines,
Reporter: c.Reporter(),
Text: fmt.Sprintf("%s would trigger %d alert(s) in the last %s.", promText(c.prom.Name(), qr.URI), alerts, output.HumanizeDuration(delta)),
Details: fmt.Sprintf(`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=1&g0.range_input=%s).`,
Details: fmt.Sprintf(`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=0&g0.range_input=%s).`,
qr.PublicURI, url.QueryEscape(rule.AlertingRule.Expr.Value.Value), output.HumanizeDuration(delta),
),
Severity: c.severity,
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func alertsText(name, uri string, count int, since string) string {

func alertsDetails(uri, query, since string) string {
return fmt.Sprintf(
`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=1&g0.range_input=%s).`,
`To get a preview of the alerts that would fire please [click here](%s/graph?g0.expr=%s&g0.tab=0&g0.range_input=%s).`,
uri, url.QueryEscape(query), since,
)
}
Expand Down
66 changes: 64 additions & 2 deletions internal/checks/promql_series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ func TestSeriesCheck(t *testing.T) {
content: `
- alert: foo
expr: |
(sum(sometimes{foo!=\"bar\"} or vector(0)))
(sum(sometimes{foo!="bar"} or vector(0)))
or
(bob > 10)
or
Expand All @@ -3353,14 +3353,76 @@ func TestSeriesCheck(t *testing.T) {
content: `
- alert: foo
expr: |
(sum(sometimes{foo!=\"bar\"} or vector(0)))
(sum(sometimes{foo!="bar"} or vector(0)))
or
((bob > 10) or sum(foo) or vector(1))
`,
checker: newSeriesCheck,
prometheus: newSimpleProm,
problems: noProblems,
},
{
description: "metric with fallback / 4",
content: `
- alert: foo
expr: |
(
sum(sometimes{foo!="bar"})
or
vector(1)
) and (
((bob > 10) or sum(bar))
or
notfound > 0
)
`,
checker: newSeriesCheck,
prometheus: newSimpleProm,
problems: func(uri string) []checks.Problem {
return []checks.Problem{
{
Lines: parser.LineRange{
First: 3,
Last: 12,
},
Reporter: checks.SeriesCheckName,
Text: noMetricText("prom", uri, "bob", "1w"),
Details: checks.SeriesCheckCommonProblemDetails,
Severity: checks.Bug,
},
{
Lines: parser.LineRange{
First: 3,
Last: 12,
},
Reporter: checks.SeriesCheckName,
Text: noMetricText("prom", uri, "bar", "1w"),
Details: checks.SeriesCheckCommonProblemDetails,
Severity: checks.Bug,
},
{
Lines: parser.LineRange{
First: 3,
Last: 12,
},
Reporter: checks.SeriesCheckName,
Text: noMetricText("prom", uri, "notfound", "1w"),
Details: checks.SeriesCheckCommonProblemDetails,
Severity: checks.Bug,
},
}
},
mocks: []*prometheusMock{
{
conds: []requestCondition{requireQueryPath},
resp: respondWithEmptyVector(),
},
{
conds: []requestCondition{requireRangeQueryPath},
resp: respondWithEmptyMatrix(),
},
},
},
}
runTests(t, testCases)
}

0 comments on commit 9e508e9

Please sign in to comment.