AnyEvent-FTP
view release on metacpan or search on metacpan
lib/Test/AnyEventFTPServer.pm view on Meta::CPAN
# 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;
=head1 DESCRIPTION
This module makes it easy to test ftp clients against a real
L<AnyEvent::FTP> FTP server. The FTP server is non-blocking in
and does not C<fork>, so if you are testing a FTP client that
blocks then you will need to do it in a separate process.
L<AnyEvent::FTP::Client> is a client that doesn't block and so
is safe to use in testing against the server.
=head1 ATTRIBUTES
=head2 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 L<URI>.
=head2 res
my $res = $test_server->res
The last L<AnyEvent::FTP::Client::Response> object returned from the
server after calling the C<command_ok> method.
=head2 content
my $content = $test_server->content
The last content retrieved from a C<list_ok>, C<nlst_ok> or C<transfer_ok>
test.
=head2 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.
=head1 METHODS
=head2 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
C<test_uri> attribute, or connect to the server using
L<AnyEvent::FTP::Client> automatically with the C<connect_ftpclient_ok>
method below.
=head2 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 L<AnyEvent::FTP::Client>
object which can be used for testing.
=head2 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 C<help_*> method for each C<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.
=head2 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 C<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
=head2 code_is
$test_server->code_is($code);
$test_server->code_is($code, $test_name);
( run in 0.444 second using v1.01-cache-2.11-cpan-39bf76dae61 )