Apache-Roaming
view release on metacpan or search on metacpan
t/10methods.t view on Meta::CPAN
sub KillHttpd { system "kill $pid" if $pid };
$SIG{'CHLD'} = sub { my $p = wait; undef $pid if $pid = $p };
$SIG{'ALRM'} = sub { KillHttpd() };
if (!open(CONF, ">$cfg->{'httpd_conf'}") ||
!(print CONF <<"EOF") || !close(CONF)) {
$cfg->{'dynamic_module_list'}
ServerRoot $cfg->{'t_dir'}
User $cfg->{'httpd_user'}
Group $cfg->{'httpd_group'}
Port $cfg->{'httpd_port'}
ServerName localhost
DocumentRoot $cfg->{'output_dir'}
PidFile $cfg->{'pid_file'}
ErrorLog $cfg->{'error_log'}
TransferLog $cfg->{'access_log'}
LockFile $cfg->{'lock_file'}
ResourceConfig $cfg->{'srm_conf'}
AccessConfig $cfg->{'access_conf'}
TypesConfig $cfg->{'types_conf'}
PerlModule Apache::Roaming
<Directory $cfg->{'roaming_dir'}>
PerlHandler Apache::Roaming->handler
PerlTypeHandler Apache::Roaming->handler_type
AuthType Basic
AuthName "Roaming User"
AuthUserFile $cfg->{'user_file'}
require valid-user
PerlSetVar BaseDir $cfg->{'roaming_dir'}
</Directory>
EOF
die "Error while writing $cfg->{'httpd_conf'}: $!";
}
if (!$pid) {
# This is the child
$ENV{'PERL5LIB'} = 'blib/arch:blib/lib';
my @opts = ($cfg->{'httpd_path'}, '-d', $cfg->{'t_dir'}, '-f',
$cfg->{'httpd_conf'}, '-X');
print "Starting httpd: ", join(" ", @opts), "\n";
exec @opts;
}
print "1..37\n";
alarm 120;
print "Creating a user agent.\n";
my $ua = LWP::UserAgent->new();
Test($ua);
sleep 5;
my $contents = 'abcdef';
my $testfile = File::Spec->catdir($cfg->{'roaming_dir'}, "foo bar", "test");
unlink $testfile;
Request($ua, 'PUT', '/roaming/foo bar/test', 'text/plain', $contents);
TestContents($testfile, $contents);
my $block = '';
for (my $i = 0; $i < 256; $i++) {
$block .= chr($i);
}
my $contents2 = $block x 40;
my $testfile2 = File::Spec->catdir($cfg->{'roaming_dir'}, "foo bar", "test2");
unlink $testfile2;
Request($ua, 'PUT', '/roaming/foo bar/test2', 'text/plain', $contents2);
TestContents($testfile2, $contents2);
my $res = Request($ua, 'GET', '/roaming/foo bar/test');
Test($res->content() and ($res->content() eq $contents));
$res = Request($ua, 'GET', '/roaming/foo bar/test2');
Test($res->content() and ($res->content() eq $contents2));
my $testfile3 = File::Spec->catdir($cfg->{'roaming_dir'}, "foo bar", "test3");
unlink $testfile3;
Request($ua, 'MOVE', '/roaming/foo bar/test', undef, undef,
'New-uri' => '/roaming/foo bar/test3');
$res = Request($ua, 'GET', '/roaming/foo bar/test3');
Test($res->content() and ($res->content() eq $contents));
Test(!-f $testfile);
my $testfile4 = File::Spec->catdir($cfg->{'roaming_dir'}, "foo bar", "test3");
unlink $testfile4;
Request($ua, 'MOVE', '/roaming/foo bar/test2', undef, undef,
'New-uri' => '/roaming/foo bar/test4');
$res = Request($ua, 'GET', '/roaming/foo bar/test4');
Test($res->content() and ($res->content() eq $contents2));
Test(!-f $testfile2);
Request($ua, 'DELETE', '/roaming/foo bar/test3');
Test(!-f $testfile3);
Request($ua, 'DELETE', '/roaming/foo bar/test4');
Test(!-f $testfile4);
sleep 5;
END {
my $status = $?;
KillHttpd();
$? = $status;
}
( run in 1.045 second using v1.01-cache-2.11-cpan-5837b0d9d2c )