Config-Model-OpenSsh
view release on metacpan or search on metacpan
t/ssh_config.t view on Meta::CPAN
# -*- cperl -*-
use ExtUtils::testlib;
use Test::More ;
use Config::Model ;
use Config::Model::BackendMgr; # required for tests
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use English;
use Test::Differences ;
use Test::Warn ;
use warnings;
use strict;
my ($model, $trace) = init_test();
# pseudo root where config files are written by config-model
my $wr_root = setup_test_dir;
my $ssh_subdir = $^O eq 'darwin' ? '/etc'
: '/etc/ssh' ;
my $ssh_path = $wr_root->child($ssh_subdir);
my @orig = <DATA> ;
$ssh_path->mkpath;
my $ssh_file = $ssh_path->child('ssh_config');
$ssh_file->spew(@orig);
# special global variable used only for tests
my $joe_home = $^O eq 'darwin' ? '/Users/joe'
: '/home/joe' ; ;
Config::Model::BackendMgr::_set_test_home($joe_home) ;
# set up Joe's environment
my $joe_ssh = $wr_root->child($joe_home.'/.ssh');
$joe_ssh->mkpath;
my $joe_config = $joe_ssh->child('config');
$joe_config->spew("Host mine.bar\n\nIdentityFile ~/.ssh/mine\n") ;
sub read_user_ssh {
my $file = shift ;
my $clean = sub {
my $l = shift;
chomp $l;
return $l =~ s/\s+/ /gr;
};
my @res = grep {/\w/} map { $clean->($_) ;} grep { not /##/ } $file->lines ;
return @res ;
}
print "Test from directory $wr_root\n" if $trace ;
note "Running test like root (no layered config)" ;
my $root_inst = $model->instance (
root_class_name => 'SystemSsh',
instance_name => 'root_ssh_instance',
root_dir => $wr_root,
);
ok($root_inst,"Read $ssh_file and created instance") ;
my $root_cfg = $root_inst -> config_root ;
$root_cfg->init ;
my $dump = $root_cfg->dump_tree ();
print $dump if $trace ;
( run in 1.766 second using v1.01-cache-2.11-cpan-39bf76dae61 )