Test::AnyEventFTPServer(3pm)

NAME
Test::AnyEventFTPServer - Test (non-blocking) ftp clients against a real FTP server

VERSION
version 0.20

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
 # from that last HELP command
 my $res = $test_server->res;

 # $client isa AnyEvent::FTP::Client
 my $client = $test_server->connect_ftpclient_ok;

 # check to make sure that all FTP commands have help
 $test_server->help_coverage_ok;

 done_testing;

DESCRIPTION
This module makes it easy to test ftp clients against a real AnyEvent::FTP FTP server. The FTP server is non-blocking in and does not "fork", so if you are testing a FTP client that blocks then you will need to do it in a separate process. AnyEvent::FTP::Client is a client that doesn't block and so is safe to use in testing against the server.

ATTRIBUTES

  test_uri
 my $uri = $test_server->test_uri

The full URL (including host, port, username and password) of the test ftp server. This is returned as URI.

  res
 my $res = $test_server->res

The last AnyEvent::FTP::Client::Response object returned from the server after calling the "command_ok" method.

  content
 my $content = $test_server->content

The last content retrieved from a "list_ok", "nlst_ok" or "transfer_ok" test.

  auto_login
 my $bool = $test_server->auto_login

If true (the default) automatically login using the correct credentials. Normally if you are testing file transfers you want to keep this to the default value, if you are testing the authentication of a server context then you want to set this to false.

METHODS

  create_ftpserver_ok
 my $test_server = create_ftpserver_ok;
 my $test_server = create_ftpserver_ok($default_context);
 my $test_server = create_ftpserver_ok($default_context, $test_name);

Create the FTP server with a random username and password for logging in. You can get the username/password from the "test_uri" attribute, or connect to the server using AnyEvent::FTP::Client automatically with the "connect_ftpclient_ok" method below.

  connect_ftpclient_ok
 my $client = $test_server->connect_ftpclient_ok;
 my $client = $test_server->connect_ftpclient_ok($test_name);

Connect to the FTP server, return the AnyEvent::FTP::Client object which can be used for testing.

  help_coverage_ok
 $test_server->help_coverage_ok;
 $test_server->help_coverage_ok($context_class);
 $test_server->help_coverage_ok($context_class, $test_name);

Test that there is a "help_*" method for each "cmd_*" method in the given context class (the server's default context class is used if it isn't provided). This can also be used to test help coverage of context roles.

  command_ok
 $test_command->command_ok( $command, $arguments );
 $test_command->command_ok( $command, $arguments, $test_name );

Execute the given command with the given arguments on the remote server. Fails only if a valid FTP response is not returned from the server (even error responses are okay).

The response is stored in the "res" attribute.

This method returns the test server object, so you can chain this command:

 $server->command_ok('HELP', 'HELP') # get help on the help command
        ->code_is(214)               # returns status code 214
        ->message_like(qr{HELP});    # the help command mentions the help command

  code_is
 $test_server->code_is($code);
 $test_server->code_is($code, $test_name);

Verifies that the status code of the last command executed matches the given code exactly.

  code_like
 $test_server->code_like($regex);
 $test_server->code_like($regex, $test_name);

Verifies that the status code of the last command executed matches the given regular expression..

  message_like
 $test_server->message_like($regex);
 $test_server->message_like($regex, $test_name);

Verifies that the message portion of the response of the last command executed matches the given regular expression.

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

Verifies that the message portion of the response of the last command executed matches the given string.

If the response message has multiple lines, then only one of the lines needs to match the given string.

  list_ok
 $test_server->list_ok;
 $test_server->list_ok($location);
 $test_server->list_ok($location, $test_name)

Execute a the "LIST" command on the given $location and wait for the results. You can see the result using the "content" attribute or test it with the "content_is" method.

  nlst_ok
 $test_server->nlst_ok;
 $test_server->nlst_ok( $location );
 $test_server->nlst_ok( $location, $test_name );

Execute a the "NLST" command on the given $location and wait for the results. You can see the result using the "content" attribute or test it with the "content_is" method.

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

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

  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.

AUTHOR
Author: Graham Ollis <plicease@cpan.org>

Contributors:

Ryo Okamoto

Shlomi Fish

José Joaquín Atria

COPYRIGHT AND LICENSE
This software is copyright (c) 2017-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.