| 1 | package Test::Clustericious::Config; | ||||||||||||
| 2 | |||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 20 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 20 | ▶ | use Test2::Plugin::FauxHomeDir; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 20 | ▶ | use File::Glob qw( bsd_glob ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 20 | ▶ | use YAML::XS qw( DumpFile ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 20 | ▶ | use File::Path qw( mkpath ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 20 | ▶ | use Clustericious::Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 20 | ▶ | use Mojo::Loader; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 20 | ▶ | use Clustericious; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 20 | ▶ | use Test2::API qw( context ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 20 | ▶ | use base qw( Exporter ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 20 | our @EXPORT = qw( create_config_ok create_directory_ok home_directory_ok create_config_helper_ok ); | |||||||||||
| 17 | 20 | our @EXPORT_OK = @EXPORT; | |||||||||||
| 18 | 20 | our %EXPORT_TAGS = ( all => \@EXPORT ); | |||||||||||
| 19 | |||||||||||||
| 20 | 20 | my $config_dir; | |||||||||||
| 21 | |||||||||||||
| 22 | sub _init | ||||||||||||
| 23 | 20 | ▶ | { | ||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 20 | $config_dir = bsd_glob('~/etc'); | |||||||||||
| 25 | 20 | mkdir $config_dir; | |||||||||||
| 26 | |||||||||||||
| 27 | 20 | $ENV{CLUSTERICIOUS_CONF_DIR} = $config_dir; | |||||||||||
| 28 | 20 | Clustericious->_testing(1); | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 20 | ▶ | BEGIN { _init() } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | |||||||||||||
| 33 | # ABSTRACT: Test Clustericious::Config | ||||||||||||
| 34 | 20 | our $VERSION = '1.29'; # VERSION | |||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | sub create_config_ok ($;$$) | ||||||||||||
| 38 | 28 | ▶ | { | ||||||||||
|
Subroutine
create_config_ok: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||
| 39 | 28 | my($config_name, $config, $test_name) = @_; | |||||||||||
| 40 | |||||||||||||
| 41 | 28 | my $fn = "$config_name.conf"; | |||||||||||
| 42 | 28 | $fn =~ s/::/-/g; | |||||||||||
| 43 | |||||||||||||
| 44 | 28 | ▶ | unless(defined $config) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | { | ||||||||||||
| 46 | 7 | my $caller = caller; | |||||||||||
| 47 | 7 | ▶ | Mojo::Loader::load_class($caller) unless $caller eq 'main'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 7 | $config = Mojo::Loader::data_section($caller, "etc/$fn"); | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 28 | my @diag; | |||||||||||
| 52 | my $config_filename; | ||||||||||||
| 53 | |||||||||||||
| 54 | 28 | my $ctx = context(); | |||||||||||
| 55 | 28 | my $ok = 1; | |||||||||||
| 56 | 28 | ▶ | if(!defined $config) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | { | ||||||||||||
| 58 | 1 | $config = "---\n"; | |||||||||||
| 59 | 1 | push @diag, "unable to locate text for $config_name"; | |||||||||||
| 60 | 1 | $ok = 0; | |||||||||||
| 61 | 1 | ▶ | $test_name //= "create config for $config_name"; | ||||||||||
|
Condition50%1/2
$test_name //= "create config for $config_name"
MC/DC0%0/1
$test_name //= "create config for $config_name"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 62 | } | ||||||||||||
| 63 | else | ||||||||||||
| 64 | { | ||||||||||||
| 65 | 27 | $config_filename = "$config_dir/$fn"; | |||||||||||
| 66 | |||||||||||||
| 67 | 27 | eval { | |||||||||||
| 68 | 27 | ▶ | if(ref $config) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | { | ||||||||||||
| 70 | 7 | DumpFile($config_filename, $config); | |||||||||||
| 71 | } | ||||||||||||
| 72 | else | ||||||||||||
| 73 | { | ||||||||||||
| 74 | 20 | open my $fh, '>', $config_filename; | |||||||||||
| 75 | 20 | print $fh $config; | |||||||||||
| 76 | 20 | close $fh; | |||||||||||
| 77 | } | ||||||||||||
| 78 | }; | ||||||||||||
| 79 | 27 | ▶ | if(my $error = $@) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | { | ||||||||||||
| 81 | 0 | $ok = 0; | |||||||||||
| 82 | 0 | push @diag, "exception: $error"; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 27 | ▶ | $test_name //= "create config for $config_name at $config_filename"; | ||||||||||
|
Condition50%1/2
$test_name //= "create config for $config_name at $config_filename"
MC/DC0%0/1
$test_name //= "create config for $config_name at $config_filename"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 86 | |||||||||||||
| 87 | # remove any cached copy if necessary | ||||||||||||
| 88 | 27 | Clustericious->_config_uncache($config_name); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 28 | $ctx->ok($ok, $test_name); | |||||||||||
| 92 | 28 | $ctx->diag($_) for @diag; | |||||||||||
| 93 | |||||||||||||
| 94 | 28 | $ctx->release; | |||||||||||
| 95 | |||||||||||||
| 96 | 28 | return $config_filename; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | |||||||||||||
| 100 | sub create_directory_ok ($;$) | ||||||||||||
| 101 | 3 | ▶ | { | ||||||||||
|
Subroutine
create_directory_ok: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 102 | 3 | my($path, $test_name) = @_; | |||||||||||
| 103 | |||||||||||||
| 104 | 3 | my $fullpath; | |||||||||||
| 105 | my $ok; | ||||||||||||
| 106 | |||||||||||||
| 107 | 3 | ▶ | if(defined $path) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | { | ||||||||||||
| 109 | 2 | $fullpath = $path; | |||||||||||
| 110 | 2 | $fullpath =~ s{^/}{}; | |||||||||||
| 111 | 2 | $fullpath = bsd_glob("~/$fullpath"); | |||||||||||
| 112 | 2 | mkpath $fullpath, 0, 0700; | |||||||||||
| 113 | |||||||||||||
| 114 | 2 | ▶ | $test_name //= "create directory $fullpath"; | ||||||||||
|
Condition50%1/2
$test_name //= "create directory $fullpath"
MC/DC0%0/1
$test_name //= "create directory $fullpath"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 115 | 2 | $ok = -d $fullpath; | |||||||||||
| 116 | } | ||||||||||||
| 117 | else | ||||||||||||
| 118 | { | ||||||||||||
| 119 | 1 | ▶ | $test_name //= "create directory [undef]"; | ||||||||||
|
Condition50%1/2
$test_name //= "create directory [undef]"
MC/DC0%0/1
$test_name //= "create directory [undef]"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 120 | 1 | $ok = 0; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | 3 | my $ctx = context(); | |||||||||||
| 124 | 3 | $ctx->ok($ok, $test_name); | |||||||||||
| 125 | 3 | $ctx->release; | |||||||||||
| 126 | 3 | return $fullpath; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | |||||||||||||
| 130 | sub home_directory_ok (;$) | ||||||||||||
| 131 | 3 | ▶ | { | ||||||||||
|
Subroutine
home_directory_ok: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 132 | 3 | my($test_name) = @_; | |||||||||||
| 133 | |||||||||||||
| 134 | 3 | my $fullpath = bsd_glob('~'); | |||||||||||
| 135 | |||||||||||||
| 136 | 3 | ▶ | $test_name //= "home directory $fullpath"; | ||||||||||
|
Condition50%1/2
$test_name //= "home directory $fullpath"
MC/DC0%0/1
$test_name //= "home directory $fullpath"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 137 | |||||||||||||
| 138 | 3 | my $ctx = context(); | |||||||||||
| 139 | 3 | $ctx->ok(-d $fullpath, $test_name); | |||||||||||
| 140 | 3 | $ctx->release; | |||||||||||
| 141 | 3 | return $fullpath; | |||||||||||
| 142 | } | ||||||||||||
| 143 | |||||||||||||
| 144 | |||||||||||||
| 145 | sub create_config_helper_ok ($$;$) | ||||||||||||
| 146 | 2 | ▶ | { | ||||||||||
|
Subroutine
create_config_helper_ok: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 147 | 2 | my($helper_name, $helper_code, $test_name) = @_; | |||||||||||
| 148 | |||||||||||||
| 149 | 2 | ▶ | $test_name //= "create config helper $helper_name"; | ||||||||||
|
Condition50%1/2
$test_name //= "create config helper $helper_name"
MC/DC0%0/1
$test_name //= "create config helper $helper_name"
$test_name
Truth table50%1/2
A
A= $test_name
| |||||||||||||
| 150 | 2 | my $ok = 1; | |||||||||||
| 151 | |||||||||||||
| 152 | 2 | require Clustericious::Config::Helpers; | |||||||||||
| 153 | 2 | do { | |||||||||||
| 154 | 20 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 155 | 2 | *{"Clustericious::Config::Helpers::$helper_name"} = $helper_code; | |||||||||||
| 156 | }; | ||||||||||||
| 157 | 2 | push @Clustericious::Config::Helpers::EXPORT, $helper_name; | |||||||||||
| 158 | |||||||||||||
| 159 | 2 | my $ctx = context(); | |||||||||||
| 160 | 2 | $ctx->ok($ok, $test_name); | |||||||||||
| 161 | 2 | $ctx->release; | |||||||||||
| 162 | 2 | return $ok; | |||||||||||
| 163 | } | ||||||||||||
| 164 | |||||||||||||
| 165 | 20 | 1; | |||||||||||
| 166 | |||||||||||||
| 167 | __END__ | ||||||||||||