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 {
    open my $fh, '<', '/etc/services';
    map { [split /\s+/]->[0] } grep /^(..)?ftp\s/, <$fh>;
  };

  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);

    my $old = $test_root->file('t', 'lib.pl');
    my $new = $dir->file('lib.pl');
    symlink $old, $new;

    $old = $remote_config;
    $new = $dir->file('config.yml');

    my $config = LoadFile($old);
    DumpFile($new, $config);

  }



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