pf-tools/pf-tools: add 15.addfile.t test script

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Dec 12 12:14:37 UTC 2014


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/c345a5c87907
changeset: 1380:c345a5c87907
user:      melkor <melkor at sitadelle.com>
date:      Fri Dec 12 13:14:34 2014 +0100
description:
add 15.addfile.t test script

diffstat:

 t/15.addfile.t |  128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 128 insertions(+), 0 deletions(-)

diffs (132 lines):

diff -r 3e98409d7538 -r c345a5c87907 t/15.addfile.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/15.addfile.t	Fri Dec 12 13:14:34 2014 +0100
@@ -0,0 +1,128 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Cwd;
+use Data::Dumper;
+use English qw( -no_match_vars );    # Avoids regex performance penalty
+use File::Copy;
+use File::Path qw( make_path remove_tree );
+use Hash::Merge::Simple qw( clone_merge merge );
+use IO::File;
+use Sys::Hostname;
+use Test::Exception;
+use Test::More qw( no_plan );
+
+use PFTools::Conf;
+use PFTools::Structqueries;
+use PFTools::Update::ADDFILE;
+
+########################################################################
+
+my $test_config_file = 't/13.conf.cfg1/etc/pf-tools.1.conf';
+my $test_pf_config
+    = init_pf_config($test_config_file);    # already tested OK above
+
+my $cwd             = getcwd;
+my $test_config_dir = qq{$cwd/t/13.conf.cfg1};
+my $test_hostname   = q{cbv4-spawn00};
+my $test_hash_subst
+    = init_subst( $test_hostname, undef, $test_pf_config, 'private' );
+
+# bypass cvs/svn/whatever for the moment
+unlink q{/tmp/pf-test/var/lib/cvsguest/config};
+make_path(q{/tmp/pf-test/var/lib/cvsguest});
+symlink qq{$cwd/t/13.conf.cfg1/config-export},
+    q{/tmp/pf-test/var/lib/cvsguest/config}
+    or diag qq{symlink: $OS_ERROR};
+
+my $parsed_configuration
+    = init_global_netconfig( q{COMMON:private-network}, $test_hash_subst );
+
+#    print Dumper($parsed_configuration);
+########################################################################
+note('Testing PFTools::Update::ADDFILE');
+
+can_ok( 'PFTools::Update::ADDFILE', qw( __find_source action_exec ) );
+
+my $global_config = $parsed_configuration;
+my ( $result, $expected_result);
+
+
+my $rh_option = {
+    host    => 'cbv4-spawn00',
+    simul   => 1,
+};
+
+my $machine_parsed_configuration = get_config_for_hostname_on_site(
+    'cbv4-spawn00', 'cbv4-pfds', $test_hash_subst, $global_config,
+    $test_pf_config
+);
+
+#print Dumper $machine_parsed_configuration;
+
+$expected_result = q{/tmp/pf-test/var/lib/cvsguest/config/FILE/spawn/etc/apt/apt-ftp-ubuntu.conf};
+$result = PFTools::Update::ADDFILE::__find_source($rh_option, $test_hash_subst, [ q{/etc/apt/apt-ftp-ubuntu.conf} ] );
+
+is $result, $expected_result
+    => q{get '/etc/apt/apt-ftp-ubuntu.conf' in 'FILE/spawn' directory}
+        or diag explain $result;
+
+$test_hash_subst->{SECTIONNAME} = q{/etc/apt/apt-ftp-ubuntu.conf};
+
+$result = PFTools::Update::ADDFILE::__find_source($rh_option, $test_hash_subst);
+
+delete $test_hash_subst->{SECTIONNAME};
+
+is $result, $expected_result
+    => q{get '/etc/apt/apt-ftp-ubuntu.conf' based on %SECTIONNAME% key in 'FILE/spawn' directory}
+        or diag explain $result;
+
+eval {
+    action_exec(
+        $machine_parsed_configuration,
+        q{/etc/apt/apt-ftp-ubuntu.conf},
+        $rh_option,
+        $test_hash_subst,
+        $global_config
+    );
+};
+
+delete $machine_parsed_configuration->{q{/etc/apt/apt-ftp-ubuntu.conf}}{source};
+eval {
+    action_exec(
+        $machine_parsed_configuration,
+        q{/etc/apt/apt-ftp-ubuntu.conf},
+        $rh_option,
+        $test_hash_subst,
+        $global_config
+    );
+};
+
+$expected_result = $test_hash_subst->{SOURCE};
+
+is $result, $expected_result
+    => q{get '/etc/apt/apt-ftp-ubuntu.conf' in 'FILE/spawn' directory without source defined}
+        or diag explain $result;
+
+delete  $test_hash_subst->{SOURCE};
+ $machine_parsed_configuration->{q{/etc/apt/apt-ftp-ubuntu.conf}}{source} = 'AUTO:/etc/apt/apt-ftp-ubuntu.conf';
+
+eval {
+    action_exec(
+        $machine_parsed_configuration,
+        q{/etc/apt/apt-ftp-ubuntu.conf},
+        $rh_option,
+        $test_hash_subst,
+        $global_config
+    );
+};
+
+$expected_result = $test_hash_subst->{SOURCE};
+
+is $result, $expected_result
+    => q{get '/etc/apt/apt-ftp-ubuntu.conf' in 'FILE/spawn' directory with AUTO shortcut}
+        or diag explain $result;
+
+__END__



More information about the pf-tools-commits mailing list