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
|
# -*- cperl -*-
use Test::More;
use Test::Memory::Cycle;
use Config::Model;
use File::Path;
use File::Copy;
use Test::Warn;
use Test::Exception;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use warnings;
use strict;
use lib 't/lib';
my ($model, $trace) = init_test();
# pseudo root where config files are written by config-model
my $wr_root = setup_test_dir( stringify => 1 );
$model->create_config_class(
'rw_config' => {
'auto_create' => '1',
'file' => 'control.pl',
'backend' => 'perl_file',
'config_dir' => 'debian'
},
'name' => 'Test::Control',
'element' => [ 'source' => { 'type' => 'leaf', value_type => 'string', } ]
);
$model->create_config_class(
'rw_config' => {
'auto_create' => '1',
'file' => 'copyright.pl',
'backend' => 'perl_file',
'config_dir' => 'debian'
},
'name' => 'Test::Copyright',
'element' => [ 'Format', { 'value_type' => 'uniline', 'type' => 'leaf', }, ]
);
$model->create_config_class(
'rw_config' => {
'auto_create' => '1',
'backend' => 'PlainFile',
'config_dir' => 'debian/source'
},
'name' => 'Test::Source',
'element' => [ 'format', { 'value_type' => 'uniline', 'type' => 'leaf', } ]
);
$model->create_config_class(
'rw_config' => {
auto_create => 1,
auto_delete => 1,
# test minimal spec with custom backend class
backend => 'Mini'
},
'name' => 'Test::Meta',
'element' => [ 'email', { 'value_type' => 'uniline', 'type' => 'leaf', } ]
);
$model->create_config_class(
'name' => 'Test::Dpkg',
'element' => [
control => {
type => 'node',
config_class_name => 'Test::Control'
},
copyright => {
type => 'node',
config_class_name => 'Test::Copyright'
},
source => {
type => 'node',
config_class_name => 'Test::Source'
},
meta => {
type => 'node',
config_class_name => 'Test::Meta'
},
]
);
my $inst = $model->instance( root_class_name => 'Test::Dpkg', root_dir => $wr_root, );
my $root = $inst->config_root;
$root->load(
'control source=ctrl-source -
copyright Format=copyright-format -
source format=source-format -
meta email=joe@foo.com'
);
ok( 1, "loaded data" );
my $dump = $root->dump_tree;
print $dump if $trace;
$inst->write_back;
#check written files
foreach (qw!control.pl copyright.pl source/format meta/test.yml!) {
my $f = $wr_root . "debian/$_";
ok( -e $f, "check written file $f" );
}
my $inst2 = $model->instance(
root_class_name => 'Test::Dpkg',
root_dir => $wr_root,
instance_name => 'test2'
);
my $root2 = $inst2->config_root;
my $dump2 = $root2->dump_tree;
is( $dump2, $dump, "check that inst2 is a copy of first instance" );
memory_cycle_ok($model, "check memory cycles");
done_testing;
|