File: 02labels.t

package info (click to toggle)
libnet-prometheus-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 1,847; makefile: 8
file content (68 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download
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
65
66
67
68
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Net::Prometheus::Metric;

# samples
{
   my $metric = Net::Prometheus::Metric->new(
      name => "basename",
      help => "",
      labels => [qw( labelname )],
   );

   # TODO: child instances are still undocumented
   my $sample = $metric->make_sample(
      undef, $metric->labels( "value" )->labelkey, 123
   );

   is( $sample->varname, "basename",                     '$sample->varname' );
   is( $sample->labels, [ labelname => "value" ], '$sample->labels' );
   is( $sample->value, 123,                              '$sample->value' );

   is(
      $metric->make_sample(
         undef, $metric->labels( "value" )->labelkey, 123, [ another => "label" ],
      )->labels,
      [ labelname => "value", another => "label" ],
      '$sample->labels with morelabels'
   );
}

# exceptions
{
   ok( dies {
         Net::Prometheus::Metric->new(
            name => "metric",
            labels => [ "ab/cd" ],
            help => "",
         )
      }, 'Invalid label name dies'
   );

   ok( dies {
         Net::Prometheus::Metric->new(
            name => "metric",
            labels => [ "__name" ],
            help => "",
         )
      }, 'Reserved label name dies'
   );

   ok( dies {
         my $metric = Net::Prometheus::Metric->new(
            name => "metric",
            labels => [ "label" ],
            help => "",
         );

         $metric->labels( "" );
      }, 'Empty label value dies'
   );
}

done_testing;