Filesys-Virtual-SSH

 view release on metacpan or  search on metacpan

t/vs_plain.t  view on Meta::CPAN

#!perl
use strict;
use warnings;
my $count;
BEGIN { $count = 40 };
use Test::More tests => $count * 2;
use Filesys::Virtual::Plain;
use Filesys::Virtual::SSH;
use File::Slurp::Tree;
use Cwd;
use Sys::Hostname;

if (eval { require Test::Differences; 1 }) {
    no warnings 'redefine';
    *is_deeply = \&Test::Differences::eq_or_diff;
}

# A comparitive test against Filesys::Virtual::Plain, more so I
# understand the api as Filesys::Virtual is low on docs

my $tree = {
    foo => "I r foo\n",
    bar => {
        baz => "I r not foo\n",
    },
};

SKIP:
for my $class (map { "Filesys::Virtual::$_" } qw( Plain SSH )) {
    if ($class =~ /::SSH$/ && hostname ne 'brains') {
        skip( "Not on brains, not doing SSH testing", $count );
    }
    my $root = cwd().'/t/test_root';
    # ick
    `rm -rf $root`;
    spew_tree( $root => $tree );
    isa_ok( my $vfs = $class->new({
        host      => 'localhost',
        cwd       => '/',
        root_path => $root,
        home_path => '/home',
    }), $class );

    is( $vfs->cwd, "/", "cwd" );
    is_deeply( [ $vfs->list( "/" ) ],
               [ sort qw( . .. ), keys %$tree ],
               "list /" );

    is_deeply( [ $vfs->list( "" ) ],
               [ sort qw( . .. ), keys %$tree ],
               "list ''" );

    is_deeply( [ $vfs->list( "foo" ) ],
               [ "foo" ],
               "list foo" );

    is_deeply( [ $vfs->list( "i_do_not_exist" ) ],
               [ ],
               "list i_do_not_exist" );

    is_deeply( [ $vfs->list( "/bar" ) ],
               [ sort qw( . .. ), keys %{ $tree->{bar} } ],
               "list /bar" );

    is_deeply( [ $vfs->list( "/bar" ) ],
               [ sort qw( . .. ), keys %{ $tree->{bar} } ],
               "list bar" );

    is( $vfs->chdir( 'bar' ), "/bar", "chdir bar" );
    is( $vfs->cwd, "/bar", "cwd is /bar" );

    is_deeply( [ $vfs->list( "" ) ],
               [ sort qw( . .. ), keys %{ $tree->{bar} } ],
               "list ''" );



( run in 1.366 second using v1.01-cache-2.11-cpan-39bf76dae61 )