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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
# -*- cperl -*-
use warnings FATAL => qw(all);
use ExtUtils::testlib;
use Test::More tests => 14;
use Test::Exception;
use Test::Memory::Cycle;
use Config::Model;
use Log::Log4perl qw(:easy);
use strict;
my ( $log, $show ) = (0) x 3;
my $arg = shift || '';
my $trace = $arg =~ /t/ ? 1 : 0;
$::debug = 1 if $arg =~ /d/;
$log = 1 if $arg =~ /l/;
$show = 1 if $arg =~ /s/;
Config::Model::Exception::Any->Trace(1) if $arg =~ /e/;
my $home = $ENV{HOME} || "";
my $log4perl_user_conf_file = "$home/.log4config-model";
if ( $log and -e $log4perl_user_conf_file ) {
Log::Log4perl::init($log4perl_user_conf_file);
}
else {
Log::Log4perl->easy_init( $arg =~ /l/ ? $DEBUG : $WARN );
}
ok( 1, "Compilation done" );
# minimal set up to get things working
my $model = Config::Model->new( legacy => 'ignore', );
$model->create_config_class(
name => 'CommonOptions',
element => [
atime => {
value_type => 'boolean',
type => 'leaf'
},
],
);
$model->create_config_class(
name => 'NoneOptions',
element => [
bind => {
value_type => 'boolean',
type => 'leaf',
},
],
);
$model->create_config_class(
name => 'Master',
element => [
fs_vfstype => {
value_type => 'enum',
type => 'leaf',
choice => [ 'auto', 'none', ]
},
fs_mntopts => {
follow => { fst => '- fs_vfstype' },
type => 'warped_node',
rules => [
'$fst eq \'auto\'',
{ config_class_name => 'Fstab::CommonOptions' },
'$fst eq \'none\'',
{ config_class_name => 'Fstab::NoneOptions' },
],
},
fs_passno => {
value_type => 'integer',
default => 0,
type => 'leaf',
warp => {
follow => {
fstyp => '- fs_vfstype',
isbound => '- fs_mntopts bind',
},
rules => [ '$fstyp eq "none" and $isbound' => { max => 0, } ]
}
},
type => {
type => 'leaf',
value_type => 'enum',
choice => [qw/node warped_node hash list leaf check_list/],
mandatory => 1,
},
cargo => {
type => 'warped_node',
level => 'hidden',
follow => { 't' => '- type' },
'rules' => [
'$t eq "list" or $t eq "hash"' => {
level => 'normal',
config_class_name => 'CommonOptions',
},
],
},
]
);
ok( 1, "compiled" );
my $inst = $model->instance(
root_class_name => 'Master',
instance_name => 'test1'
);
ok( $inst, "created dummy instance" );
$inst->initial_load_stop ;
my $root = $inst->config_root;
my $pass = $root->fetch_element('fs_passno');
is( $pass->fetch, '0', "check pass nb at 0" );
$pass->store(2);
is( $pass->fetch, '2', "check pass nb at 2" );
$root->load('fs_vfstype=none');
is( $pass->fetch, '2', "check pass nb at 2 after setting fs_vfstype" );
$root->load('fs_mntopts bind=1');
throws_ok { $pass->fetch; } 'Config::Model::Exception::WrongValue',
"check that setting bind detects and error with passno";
# fix issue
$root->load('fs_mntopts bind=1 - fs_passno=0 fs_mntopts bind=0');
is( $pass->fetch, '0', "check pass nb at 2 after setting bind" );
# warp out bind
$root->load('fs_vfstype=auto');
throws_ok { $root->load('fs_mntopts bind=1'); }
'Config::Model::Exception::UnknownElement',
"check that setting bind was warped out";
# fix issue
$root->load('fs_vfstype=none fs_mntopts bind=0 - fs_passno=3');
is( $pass->fetch, '3', "check pass nb at 3 " );
# break again
$root->load('fs_mntopts bind=1');
throws_ok { $pass->fetch; } 'Config::Model::Exception::WrongValue',
"check that setting bind detects and error with passno again";
$root->load('fs_passno=0 fs_mntopts bind=1');
is( $pass->fetch, '0', "check pass nb at 2 after setting bind" );
ok($root->load('type=hash cargo atime=1'), "check warping in of a node");
memory_cycle_ok($model);
|