Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit Test Rules Hook #1

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@
args:
- check
- rules

- id: test-rules
stages: [commit]
name: Unit test prometheus rule files
description: Unit test prometheus rule files
language: docker_image
entry: --entrypoint /bin/promtool prom/prometheus:latest
files: ^$
args:
- test
- rules
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ To lint Prometheus Config files, use the `prometheus-config` hook. Make sure to
(?x)^(
config_directory/.*\.yml
)$

To unit-test Prometheus Rule files, use the `test-rules` hook. Make sure to filter files passed to hook by defining the `files` section. Note: the `entry` option below is optional and will default to the latest prometheus version. It is shown just as an example of pinning to a specific prometheus version.

In the example provided, we are setting this to always run as rule files could be changed without altering the unit tests. Unit tests should be run against their respective rule files after any change.

- repo: https://github.com/fortman/pre-commit-prometheus
rev: v1.2.0
hooks:
- id: test-rules
entry: --entrypoint /bin/promtool prom/prometheus:v2.18.2
always_run: true
files: >
(?x)^(
unit_test_directory/.*\.yml
)$