File: instance-reset.t

package info (click to toggle)
libconfig-model-perl 2.155-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,172 kB
  • sloc: perl: 15,117; makefile: 19
file content (79 lines) | stat: -rw-r--r-- 1,789 bytes parent folder | download | duplicates (3)
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

use warnings;
use strict;

use Test::More;
use Test::Memory::Cycle;
use Config::Model;
use Config::Model::Tester::Setup qw/init_test  setup_test_dir/;

use lib "t/lib";

sub check {
    my ($node, $msg) = @_;
    is($node->grab_value('foo:0'),'foo1',"$msg: foo:0 is set");
    is($node->grab_value('class1 lista:0'),'lista1',"$msg: lista:0 is set");
    is($node->grab_value('class1 listb:0'),undef,"$msg: listb:0 is not set");
    is($node->instance->needs_save,0, "$msg: instance has no data to save");
}

my ($model, $trace) = init_test();

# pseudo root where config files are written by config-model
my $wr_root = setup_test_dir();

# set_up data
my @ini_data = <DATA>;

my $test1     = 'ini1';
my $wr_dir    = $wr_root->child($test1);
my $etc_dir   = $wr_dir->child('etc');
$etc_dir->mkpath;
my $conf_file = $etc_dir->child("test.ini");
$conf_file->remove;

$conf_file->spew_utf8(@ini_data);

my $i_test = $model->instance(
    instance_name   => 'to_reset',
    root_class_name => 'IniTest',
    root_dir        => $wr_dir,
    model_file      => 'test_ini_backend_model.pl',
);

ok( $i_test, "Created instance" );

my $i_root = $i_test->config_root;
ok( $i_root, "created tree root" );
$i_root->init;
ok( 1, "root init done" );

check($i_root, "before reset");

my $dump = $i_root->dump_tree;
print "Before reset:\n",$dump if $trace;

$i_root->load("foo:=blork1 class1 listb:=blork");

ok($i_root->needs_save, "instance has something to save");

my $new_root = $i_test->reset_config;

ok(1, "config was reset");

check($new_root, "after reset");

is($new_root->dump_tree, $dump, "check dump tree after reset");

ok($i_root->needs_save, "instance has something to save");

memory_cycle_ok( $model, "memory cycle test" );

done_testing;

__DATA__
foo = foo1

[class1]

lista=lista1