File: 20-declare.t

package info (click to toggle)
libprometheus-tiny-perl 0.011-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 180 kB
  • sloc: perl: 746; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!perl

use warnings;
use strict;

use Test::More;

use Prometheus::Tiny;

{
  my $p = Prometheus::Tiny->new;
  $p->declare('some_metric', help => 'My great metric');
  is $p->format, <<EOF, 'metric help formatted correctly';
# HELP some_metric My great metric
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->declare('some_metric', type => 'counter');
  is $p->format, <<EOF, 'metric type formatted correctly';
# TYPE some_metric counter
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->declare('some_metric', help => 'My great metric', type => 'counter');
  is $p->format, <<EOF, 'metric help & type formatted correctly';
# HELP some_metric My great metric
# TYPE some_metric counter
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->declare('some_metric', help => 'My great metric', type => 'counter');
  $p->declare('other_metric', help => 'My other great metric', type => 'gauge');
  $p->set('some_metric', 5);
  $p->set('other_metric', 10);
  is $p->format, <<EOF, 'multiple metric help & type formatted correctly';
# HELP other_metric My other great metric
# TYPE other_metric gauge
other_metric 10
# HELP some_metric My great metric
# TYPE some_metric counter
some_metric 5
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->declare('some_metric', help => 'My great metric', type => 'counter');
  $p->set('some_metric', 5);
  $p->set('other_metric', 10);
  is $p->format, <<EOF, 'multiple metric single help & type formatted correctly';
other_metric 10
# HELP some_metric My great metric
# TYPE some_metric counter
some_metric 5
EOF
}

done_testing;