-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more test coverage for checkstyle
- Loading branch information
Showing
9 changed files
with
177 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
! exec pint --no-color lint --checkstyle=x/y/z/checkstyle.xml rules | ||
! stdout . | ||
cmp stderr stderr.txt | ||
|
||
-- stderr.txt -- | ||
level=INFO msg="Finding all rules to check" paths=["rules"] | ||
level=ERROR msg="Fatal error" err="open x/y/z/checkstyle.xml: no such file or directory" | ||
-- rules/0001.yml -- | ||
groups: | ||
- name: test | ||
rules: | ||
- alert: Example | ||
expr: up | ||
- alert: Example | ||
expr: sum(xxx) with() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
mkdir testrepo | ||
cd testrepo | ||
exec git init --initial-branch=main . | ||
|
||
cp ../src/v1.yml rules.yml | ||
cp ../src/.pint.hcl . | ||
env GIT_AUTHOR_NAME=pint | ||
env GIT_AUTHOR_EMAIL=pint@example.com | ||
env GIT_COMMITTER_NAME=pint | ||
env GIT_COMMITTER_EMAIL=pint@example.com | ||
exec git add . | ||
exec git commit -am 'import rules and config' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/v2.yml rules.yml | ||
exec git commit -am 'v2' | ||
|
||
exec pint -l debug --offline --no-color ci --checkstyle=checkstyle.xml | ||
! stdout . | ||
cmp checkstyle.xml ../checkstyle_expected.xml | ||
|
||
-- src/v1.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/v2.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} | ||
|
||
-- checkstyle_expected.xml -- | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<checkstyle version="4.3"> | ||
<file name="rules.yml"> | ||
<error line="2" severity="Warning" message="Alert query doesn't have any condition, it will always fire if the metric exists.
Prometheus alerting rules will trigger an alert for each query that returns *any* result.
Unless you do want an alert to always fire you should write your query in a way that returns results only when some condition is met.
In most cases this can be achieved by having some condition in the query expression.
For example `up == 0` or `rate(error_total[2m]) > 0`.
Be careful as some PromQL operations will cause the query to always return the results, for example using the [bool modifier](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators)." source="alerts/comparison"></error> | ||
<error line="3" severity="Information" message="`0s` is the default value of `for`, consider removing this redundant line." source="alerts/for"></error> | ||
</file> | ||
</checkstyle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
mkdir testrepo | ||
cd testrepo | ||
exec git init --initial-branch=main . | ||
|
||
cp ../src/v1.yml rules.yml | ||
cp ../src/.pint.hcl . | ||
env GIT_AUTHOR_NAME=pint | ||
env GIT_AUTHOR_EMAIL=pint@example.com | ||
env GIT_COMMITTER_NAME=pint | ||
env GIT_COMMITTER_EMAIL=pint@example.com | ||
exec git add . | ||
exec git commit -am 'import rules and config' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/v2.yml rules.yml | ||
exec git commit -am 'v2' | ||
|
||
! exec pint --offline --no-color ci --checkstyle=x/y/z/checkstyle.xml | ||
! stdout . | ||
cmp stderr ../stderr.txt | ||
|
||
-- src/v1.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/v2.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} | ||
|
||
-- stderr.txt -- | ||
level=INFO msg="Loading configuration file" path=.pint.hcl | ||
level=INFO msg="Finding all rules to check on current git branch" base=main | ||
level=INFO msg="Offline mode, skipping Prometheus discovery" | ||
level=ERROR msg="Fatal error" err="open x/y/z/checkstyle.xml: no such file or directory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters