File: validate_keys.t

package info (click to toggle)
libconfigreader-simple-perl 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 220 kB
  • ctags: 27
  • sloc: perl: 657; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More 'no_plan';

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
my $class  = 'ConfigReader::Simple';
my $method = '_validate_keys';

use_ok( $class );
can_ok( $class, $method );

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it works if validkeys is not set
{
my $config = bless {}, $class; # a mock, nothing set

ok( $config->$method(), "$method returns true without validkeys set" );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it works if validkeys is set, but not an array reference
{
my $config = bless { validkeys => 4 }, $class; # a mock, nothing set

eval { $config->$method() };
my $at = $@;
ok( length $at, 'eval fails when validkeys is not an aray ref' );
like( $at, qr/not an array reference/, "Passing non array ref fails" );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it works if validkeys is set, but missing in config
{
my $config = bless { validkeys => [ qw(Buster) ] }, $class; # a mock, nothing set

eval { $config->$method() };
my $at = $@;
ok( length $at, 'eval fails when Buster directive is missing' );
like( $at, qr/do not occur/, "Missing key fails" );
}