Skip to content

Commit

Permalink
Merge pull request #1137 from cloudflare/rule/duplicate
Browse files Browse the repository at this point in the history
Fix panics in rule/duplicate
  • Loading branch information
prymitive authored Oct 3, 2024
2 parents 494d27a + 8197992 commit 87bfd23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Reverted `Fixed colored output on some environments - #1106` change
as it was breaking GitHub report comments.
- Fixed panics in [rule/duplicate](checks/rule/duplicate.md) check.

## v0.65.3

Expand Down
3 changes: 3 additions & 0 deletions internal/checks/rule_duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (c RuleDuplicateCheck) Check(ctx context.Context, path discovery.Path, rule
if entry.State == discovery.Removed {
continue
}
if entry.PathError != nil {
continue
}
if entry.Rule.Error.Err != nil {
continue
}
Expand Down
9 changes: 7 additions & 2 deletions internal/checks/rule_duplicate_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package checks_test

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

"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 All @@ -32,13 +34,16 @@ func TestRuleDuplicateCheck(t *testing.T) {
problems: noProblems,
},
{
description: "ignores alerting rules",
content: "- alert: foo\n expr: up == 0\n",
description: "ignores entries with path errors",
content: "- record: foo\n expr: up == 0\n",
checker: func(prom *promapi.FailoverGroup) checks.RuleChecker {
return checks.NewRuleDuplicateCheck(prom)
},
prometheus: newSimpleProm,
problems: noProblems,
entries: []discovery.Entry{
{PathError: errors.New("Mock error")},
},
},
{
description: "ignores self",
Expand Down

0 comments on commit 87bfd23

Please sign in to comment.