AnyEvent-FTP

 view release on metacpan or  search on metacpan

inc/ServerTests.pm  view on Meta::CPAN

package inc::ServerTests;

use Moose;
use namespace::autoclean;
use 5.010;
use Path::Class qw( file dir );
use YAML qw( LoadFile DumpFile );
use File::Glob qw( bsd_glob );

with 'Dist::Zilla::Role::TestRunner';

sub test
{
  my($self, $target) = @_;

  my $test_root = dir('.')->absolute;

  my @services = do {

inc/ServerTests.pm  view on Meta::CPAN

  };

  foreach my $service (@services)
  {
    my $dir = $test_root->subdir('t', 'server', $service);
    $dir->mkpath(0,0700);
    my $old = $test_root->file('t', 'lib.pl');
    my $new = $dir->file('lib.pl');
    symlink $old, $new;

    $old = file( bsd_glob '~/etc/localhost/yml');
    $new = $dir->file('config.yml');

    my $config = LoadFile($old);
    $config->{port} = $service;
    DumpFile($new, $config);
  }

  my @remotes;

  foreach my $remote_config (grep { $_->basename =~ /\.yml$/ } dir(bsd_glob '~/etc')->children)
  {
    next if $remote_config->basename eq 'localhost.yml';
    #$self->zilla->log($remote_config->basename);

    my $name = $remote_config->basename;
    $name =~ s/\.yml$//;
    push @remotes, $name;

    my $dir = $test_root->subdir('t','server',$name);
    $dir->mkpath(0,0700);

lib/AnyEvent/FTP/Server/Context/Memory.pm  view on Meta::CPAN


with 'AnyEvent::FTP::Server::Role::Auth';
with 'AnyEvent::FTP::Server::Role::Help';
with 'AnyEvent::FTP::Server::Role::Old';
with 'AnyEvent::FTP::Server::Role::Type';
with 'AnyEvent::FTP::Server::Role::TransferPrep';


sub store
{
  # The store for this class is global.
  # if you wanted each connection or user
  # to have their own store you could subclass
  # and redefine the store method as apropriate
  state $store = {};
  $store;
}


has cwd => (
  is      => 'rw',

lib/Test/AnyEventFTPServer.pm  view on Meta::CPAN

    $ctx->diag("expected:");
    _display_content($string);
  }

  $ctx->release;

  $self;
}


sub global_timeout_ok (;$$)
{
  my($timeout, $message) = @_;

  $timeout //= 120;
  $message //= "global timeout of $timeout seconds";

  my $ctx = context();

  state $timers = [];

  eval {
    push @$timers, AnyEvent->timer(
      after => $timeout,
      cb    => sub { $ctx->diag("GLOBAL TIMEOUT"); exit },
    );

lib/Test/AnyEventFTPServer.pm  view on Meta::CPAN

  $ctx->release;

  $ok;
}

sub import
{
  my $caller = caller;
  no strict 'refs';
  *{join '::', $caller, 'create_ftpserver_ok'} = \&create_ftpserver_ok;
  *{join '::', $caller, 'global_timeout_ok'} = \&global_timeout_ok;
}

BEGIN { eval 'use EV' }

1;

__END__

=pod

lib/Test/AnyEventFTPServer.pm  view on Meta::CPAN

=head1 VERSION

version 0.19

=head1 SYNOPSIS

 use Test2:V0;
 use Test::AnyEventFTPServer;
 
 # exit this script after 30s to avoid hung test
 global_timeout_ok;
 
 # $test_server isa AnyEvent::FTP::Server
 # and          isa Test::AnyEventFTPServer
 my $test_server = create_ftpserver_ok;
 
 $test_server->command_ok('HELP')
             ->code_is(214)
             ->message_like(qr{the following commands are recognize});
 
 # $res isa AnyEvent::FTP::Client::Response

lib/Test/AnyEventFTPServer.pm  view on Meta::CPAN

method.

=head2 content_is

 $test_server->content_is($string);
 $test_server->content_is($string, $test_name);

Test that the given C<$string> matches the content
returned by the last C<list_ok> or C<nlst_ok> method.

=head2 global_timeout_ok

 global_timeout_ok;
 global_timeout_ok($timeout);
 global_timeout_ok($timeout, $test_name)

Set a global timeout on the entire test script.  If the timeout
is exceeded the test will exit.  Handy if you have test automation
and your test automation doesn't handle hung tests.

The default timeout is 120 seconds.

=head1 AUTHOR

Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>

Contributors:

t/anyevent_ftp_client.t  view on Meta::CPAN

          <$fh>;
        };
        is $remote, $data, 'remote matches';
      };

      unlink $fn;
      ok !-e $fn, 'remote file deleted';

      do {
        my $data = 'some data';
        my $glob = do {
          my $dir = tempdir( CLEANUP => 1);
          my $fn = File::Spec->catfile($dir, 'flub.txt');
          open my $out, '>', $fn;
          binmode $out;
          print $out $data;
          close $out;
          open my $in, '<', $fn;
          binmode $in;
          $in;
        };
        my $ret = eval { $client->stor('foo.txt', $glob)->recv; };
        diag $@ if $@;
        isa_ok $ret, 'AnyEvent::FTP::Response';
        ok -e $fn, 'remote file created';
        my $remote = do {
          open my $fh, '<', $fn;
          local $/;
          <$fh>;
        };
        is $remote, $data, 'remote matches';
      };

t/anyevent_ftp_server_role_help.t  view on Meta::CPAN

use Test2::V0 -no_srand => 1;
use Test::AnyEventFTPServer;

global_timeout_ok;

foreach my $type (qw( FSRW Memory ))
{
  my $server = create_ftpserver_ok($type);
  my $client = $server->connect_ftpclient_ok;

  is $client->help->recv->code, 214, "HELP";
  is $client->help('HELP')->recv->code, 214, "HELP HELP";
  is eval { $client->help('bogus command')->recv} || $@->code, 502, "HELP bogus command";
}

t/anyevent_ftp_server_role_old.t  view on Meta::CPAN

use Test2::V0 -no_srand => 1;
use Test::AnyEventFTPServer;

global_timeout_ok;

foreach my $type (qw( FSRW Memory ))
{
  my $server = create_ftpserver_ok($type);
  my $client = $server->connect_ftpclient_ok;

  is $client->allo->recv->code, 202, "ALLO";
  is $client->noop->recv->code, 200, "NOOP";
  is $client->syst->recv->code, 215, "SYST";

t/anyevent_ftp_server_role_transferprep.t  view on Meta::CPAN

use Test2::V0 -no_srand => 1;
use AnyEvent::FTP::Server::Role::TransferPrep;
use strict;
use warnings;
use Test::AnyEventFTPServer;

global_timeout_ok(30);

foreach my $type (qw( FSRW Memory ))
{
  my $t = create_ftpserver_ok($type);

  $t->help_coverage_ok('AnyEvent::FTP::Server::Role::TransferPrep');

  $t->command_ok('REST')
    ->code_is(501)
    ->message_like(qr{REST requires});

t/lib/Test2/Tools/ClientTests.pm  view on Meta::CPAN

package Test2::Tools::ClientTests;

use strict;
use warnings;
use 5.010;
use FindBin ();
use Path::Class qw( dir file );
use Path::Class ();
use File::Spec;
use File::Glob qw( bsd_glob );
use Cwd ();
use Test2::API qw( context );
use base qw( Exporter );

our @EXPORT = qw( $config $detect prep_client translate_dir net_pwd reset_timeout );

$ENV{LC_ALL} = 'C';

our $config;
our $detect;

t/lib/Test2/Tools/ClientTests.pm  view on Meta::CPAN


$config->{dir} //= dir( -l file(__FILE__)->absolute ? file(readlink file(__FILE__))->absolute->parent : $FindBin::Bin )->parent->stringify;

do {
  my $file = file( __FILE__ )->absolute->parent->file("config.yml")->stringify;
  $ENV{AEF_CONFIG} = $file if -r $file;
};

if(defined $ENV{AEF_PORT} && ! defined $ENV{AEF_CONFIG})
{
  $ENV{AEF_CONFIG} //= file( bsd_glob '~/etc/localhost.yml' )->stringify;
}

if(defined $ENV{AEF_CONFIG})
{
  my $save = $config->{dir};
  require YAML;
  $config = YAML::LoadFile($ENV{AEF_CONFIG});
  $config->{dir} = $save if defined $save;
  $config->{dir} = Path::Class::Dir->new($config->{dir})->resolve;
  $config->{port} //= $ENV{AEF_PORT} if defined $ENV{AEF_PORT};

t/test_anyeventftpserver.t  view on Meta::CPAN

use Test2::V0 -no_srand => 1;
use Test::AnyEventFTPServer;
use File::chdir;

global_timeout_ok;

subtest 'basic' => sub {

  my $server = create_ftpserver_ok;
  isa_ok $server, 'AnyEvent::FTP::Server';
  isa_ok $server->test_uri, 'URI';

  my $client = $server->connect_ftpclient_ok;
  isa_ok $client, 'AnyEvent::FTP::Client';

tools/test_client.pl  view on Meta::CPAN

use strict;
use warnings;
use autodie;
use 5.010;
use File::Spec;
use Path::Class qw( dir );
use File::Spec;
use FindBin ();
use YAML qw( LoadFile );
use File::Glob qw( bsd_glob );

my @services = do {
  open my $fh, '<', '/etc/services';
  map { [split /\t/]->[0] } grep /^(..)?ftp\s/, <$fh>;
};

chdir dir($FindBin::Bin)->parent->stringify;

say "[self test]";
system 'prove', '-l', '-j', 3, '-r', 't', ;#'xt';

my @client_tests = map { $_->stringify } grep { $_->basename =~ /^client_.*\.t$/ } dir(File::Spec->curdir)->subdir('t')->children(no_hidden => 1);

foreach my $service (@services)
{
  local $ENV{AEF_CONFIG} = File::Spec->catfile(bsd_glob '~/.ftptest/localhost.yml');
  local $ENV{AEF_PORT} = $service;
  say "[$service]";
  system 'prove', '-l', '-j', 3, @client_tests;
}

my @list = do {
  my $dir = File::Spec->catdir(bsd_glob '~/.ftptest');
  my $dh;
  opendir DIR, $dir;
  my @list = readdir DIR;
  closedir DIR;
  map { File::Spec->catfile(bsd_glob('~/.ftptest'), $_) } grep !/^localhost\.yml$/, grep !/^\./, @list;
};

foreach my $config (@list)
{
  local $ENV{AEF_REMOTE} = LoadFile($config)->{remote};
  local $ENV{AEF_CONFIG} = $config;
  say "[$config]";
  system 'prove', '-l', '-j', 3, @client_tests;
}



( run in 0.831 second using v1.01-cache-2.11-cpan-49f99fa48dc )