Net::FTP::Mock - test code using Net::FTP without having an FTP server
version 0.103300
use Net::FTP::Mock ( localhost => { username => { password => { active => 1, root => "t/remote_ftp/" }}, }, ftp.work.com => { harry => { god => { active => 1, root => "t/other_remote_ftp/" }}, }, ); use Net::FTP; # will do nothing, since Mock already blocked it # $ftp here actually is a Net::FTP::Mock object, # but when inspected with isa() it happily claims to be Net::FTP my $ftp = Net::FTP->new("ftp.work.com", Debug => 0) or die "Cannot connect to some.host.name: $@"; # all of these do what you'd think they do, only instead of acting # on a real ftp server, they act no the data provided via import # and the local harddisk $ftp->login( "harry",'god' ) or die "Cannot login ", $ftp->message; $ftp->get("that.file") or die "get failed ", $ftp->message; $ftp->quit;
Net::FTP::Mock is designed to make code using Net::FTP testable without having to set up actual FTP servers. When calling its import(), usually by way of use, you can pass it a hash detailing virtual servers, their accounts, as well as directories that those accounts map to on the local machine.
You can then interact with the Net::FTP::Mock object exactly as you would with a real one.
NOTE: This is a work in progress and much of Net::FTP's functionality is not yet emulated. If it behaves odd, look at the code or yell at me. Contributions on github are very welcome.
test code using Net::FTP without having an FTP server
Factory method that is implanted into Net::FTP's namespace and returns a Net::FTP::Mock object. Should behave exactly like Net::FTP's new() behaves.
Class attribute that stores the servers hashref passed when the module is used.
Blocks Net::FTP's namespace in %INC and prepares the servers to be emulated.
Overrides isa to ensure that Moose's type checks recognize this as a Net::FTP object.
Thanks to Tr@ffics and especially Jens Muskewitz for granting permission to release this module.
Many thanks to mst and rjbs who fielded my newbie questions in #moose and helped me figure out how to actually create the Mock object from Net::FTP's mainspace, as well as how to get the Mock object to masquerade as Net::FTP.
Since I'm not sure how much time i can devote to this, I'm happy about any help. The code is up on github and i'll accept any helping pull requests.
Christian Walde <mithaldu@yahoo.de>
This software is Copyright (c) 2010 by Christian Walde.
This is free software, licensed under:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004
To install Net::FTP::Mock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::FTP::Mock
CPAN shell
perl -MCPAN -e shell install Net::FTP::Mock
For more information on module installation, please visit the detailed CPAN module installation guide.