Skip to content

Commit

Permalink
Merge pull request vozlt#242 from u5surf/test_display_prometheus
Browse files Browse the repository at this point in the history
test: Add test for display prometheus
  • Loading branch information
u5surf authored Sep 7, 2022
2 parents 7ef4e85 + 49b8f5e commit e3cc427
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
run: |
sudo apt install -y cpanminus
sudo cpanm install Test::Nginx::Socket
- name: 'prepare promtool'
run: |
sudo apt-get update && sudo apt-get install -y curl
curl -L $(curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4) -o prometheus-latest.tar.gz
tar xvf prometheus-latest.tar.gz
sudo mv prometheus-*/promtool /usr/local/bin
- name: 'test'
working-directory: nginx-module-vts
run: |
Expand Down
53 changes: 53 additions & 0 deletions t/022.display_prometheus.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# vi:set ft=perl ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket;

add_response_body_check(
sub {
my ($block, $body, $req_idx, $repeated_req_idx, $dry_run) = @_;
system("echo '$body' | promtool check metrics") == 0 or
bail_out "prometheus Syntax error($body)";
}
);

plan tests => repeat_each(2) * blocks() * 3;
no_shuffle();
run_tests();

__DATA__
=== TEST 1: /status/format/prometheus
--- http_config
vhost_traffic_status_zone;
--- config
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format prometheus;
}
--- request
GET /status/format/prometheus
--- response_headers_like
Content-Type: text/plain
--- response_body_like eval
[
'nginx_vts_info',
]
=== TEST 2: /status
--- http_config
vhost_traffic_status_zone;
--- config
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format prometheus;
}
--- request
GET /status
--- response_headers_like
Content-Type: text/plain
--- response_body_like eval
[
'nginx_vts_info',
]

0 comments on commit e3cc427

Please sign in to comment.