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
|
# -*- cperl -*-
use ExtUtils::testlib;
use Test::More;
use Test::Exception;
use Test::Memory::Cycle;
use Config::Model;
use Config::Model::Tester::Setup qw/init_test/;
use strict;
use warnings;
my ($model, $trace) = init_test();
$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 => {
type => 'warped_node',
warp => {
follow => { fst => '- fs_vfstype' },
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',
warp => {
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, "memory cycle");
done_testing;
|