Config-Model-Backend-Augeas

 view release on metacpan or  search on metacpan

t/augeas_backend.t  view on Meta::CPAN

# -*- cperl -*-

use warnings;
use strict;

# test augeas backend 

# workaround Augeas locale bug
if (not defined $ENV{LC_ALL} or $ENV{LC_ALL} ne 'C' or $ENV{LANG} ne 'C') {
  $ENV{LC_ALL} = $ENV{LANG} = 'C';
  # use the Perl interpreter that ran this script. See RT #116750
  exec("$^X $0 @ARGV");
}

use ExtUtils::testlib;
use Test::More ;
use Test::Differences;
use Config::Model;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use Path::Tiny;
use version 0.77 ;

use lib 't/lib';
use LoadTest;

eval { require Config::Augeas ;} ;
if ( $@ ) {
    plan skip_all => 'Config::Augeas is not installed';
}
else {
    plan tests => 18;
}

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

# pseudo root were input config file are read
my $r_root = path('augeas-box');

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

# cleanup before tests
$wr_root->child('etc/ssh')->mkpath;
$r_root->child('etc/hosts')->copy($wr_root->child('etc')) ;
$r_root->child('etc/ssh/sshd_config')->copy($wr_root->child('etc/ssh/')) ;

# set_up data
load_test_model($model);

my $i_hosts = $model->instance(
    instance_name    => 'hosts_inst',
    root_class_name  => 'Hosts',
    root_dir    => $wr_root ,
);

ok( $i_hosts, "Created instance for /etc/hosts" );

my $i_root = $i_hosts->config_root ;

my $expect = "record:0
  ipaddr=127.0.0.1
  canonical=localhost
  alias=localhost -
record:1
  ipaddr=192.168.0.1
  canonical=bilbo - -
" ;

my $dump = $i_root->dump_tree ;
print $dump if $trace ;
is( $dump , $expect,"check dump of augeas data");

# change data content, '~' is like a splice, 'record~0' like a "shift"
$i_root->load("record~0 record:0 canonical=buildbot - 
               record:1 canonical=komarr ipaddr=192.168.0.10 -
               record:2 canonical=repoman ipaddr=192.168.0.11 -
               record:3 canonical=goner   ipaddr=192.168.0.111") ;



( run in 1.887 second using v1.01-cache-2.11-cpan-5a3173703d6 )