BEGIN { $| = 1;
print
"1..187\n"
; }
END {
print
"not ok 1\n"
unless
$loaded
; }
my
$ok_count
= 1;
sub
ok {
my
$ok
=
shift
;
$ok
or
print
"not "
;
print
"ok $ok_count\n"
;
++
$ok_count
;
$ok
;
}
if
(0) {
$LWP::UA::DEBUG
= 10;
$LWP::EventLoop::DEBUG
= 10;
$LWP::Server::DEBUG
= 10;
$LWP::Conn::FTP::DEBUG
= 10;
$LWP::Conn::HTTP::DEBUG
= 10;
$LWP::Conn::_Connect::DEBUG
= 10;
$LWP::StdSched::DEBUG
= 10;
}
$loaded
= 1;
ok(1);
chdir
't'
if
-d
't'
;
ok( !WebFS::FileCopy::_is_directory(URI::file->new_abs(
'file1'
)) );
ok( !
defined
copy_urls([
'file:/a'
,
'file:/b'
],
'file:/c'
) );
ok( $@ eq
'Cannot copy many files to one file'
);
ok( !
defined
copy_urls(
'file:/tmp/'
,
'file:/tmp/'
) );
ok( $@ eq
'Cannot copy directories: file:/tmp/'
);
ok( $@ eq
'Can only copy to file or FTP URLs: http://ftp/'
);
my
$cwd
= cwd;
my
@from_files
=
qw(file1 file2 file3 file4 file5)
;
my
@from_uris
=
map
{ URI::file->new_abs(
$_
) }
@from_files
;
my
@to_uris
=
map
{ WebFS::FileCopy::_create_uri(
"$_.new"
) }
@from_uris
;
unlink
(
map
{
$_
->file }
@to_uris
);
my
@a
= get_urls(
@from_uris
);
ok(
@a
==
@from_uris
);
ok(
$a
[0] );
ok(
$a
[1] );
ok(
$a
[2] );
ok(
$a
[3] );
ok(
$a
[4] );
ok(
$a
[0]->is_success and
length
(
$a
[0]->content) == 90 );
ok(
$a
[1]->is_success and
length
(
$a
[1]->content) == 501 );
ok(
$a
[2]->is_success and
length
(
$a
[2]->content) == 365 );
ok( !
$a
[3]->is_success );
ok(
$a
[4]->is_success and
length
(
$a
[4]->content) == 11683 );
my
$content
=
$a
[4]->content;
my
@b
= put_urls(
$content
,
@to_uris
,
'file:/this/path/should/not/exist'
);
ok(
@b
==
@from_files
+1 );
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok(
$b
[5] );
ok(
$b
[0]->is_success );
ok(
$b
[1]->is_success );
ok(
$b
[2]->is_success );
ok(
$b
[3]->is_success );
ok(
$b
[4]->is_success );
ok( !
$b
[5]->is_success );
ok(
$b
[5]->message eq
"No such file or directory"
);
my
@c
= get_urls(
@to_uris
);
ok(
@c
==
@from_files
);
ok(
$a
[4] );
ok(
$a
[4]->content eq
$c
[0]->content );
ok(
$a
[4]->content eq
$c
[1]->content );
ok(
$a
[4]->content eq
$c
[2]->content );
ok(
$a
[4]->content eq
$c
[3]->content );
ok(
$a
[4]->content eq
$c
[4]->content );
my
$i
= 0;
my
$put_string
=
$a
[2]->content;
sub
put_test {
return
undef
if
$i
==
length
(
$put_string
);
substr
(
$put_string
,
$i
++, 1);
}
@b
= put_urls(\
&put_test
,
'file:/this/path/should/not/exist'
,
@to_uris
);
ok(
@b
==
@from_files
+1 );
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok(
$b
[5] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
"No such file or directory"
);
ok(
$b
[1]->is_success );
ok(
$b
[2]->is_success );
ok(
$b
[3]->is_success );
ok(
$b
[4]->is_success );
ok(
$b
[5]->is_success );
@b
= get_urls(
@to_uris
);
ok(
@b
==
@from_files
);
ok(
$a
[2] );
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok(
$a
[2]->content eq
$b
[0]->content );
ok(
$a
[2]->content eq
$b
[1]->content );
ok(
$a
[2]->content eq
$b
[2]->content );
ok(
$a
[2]->content eq
$b
[3]->content );
ok(
$a
[2]->content eq
$b
[4]->content );
@b
= put_urls(
'text'
,
''
);
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
'Invalid scheme http'
);
ok( !
$b
[1]->is_success );
ok( !
$b
[2]->is_success );
ok(
$b
[2]->message eq
"FTP return code 553"
);
ok( !
$b
[3]->is_success );
ok(
$b
[3]->message eq
"Missing URL in request"
);
@b
= delete_urls(
''
);
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
"Method Not Allowed"
);
ok( !
$b
[1]->is_success );
ok(
$b
[1]->message eq
"Use ftp instead"
);
ok( !
$b
[2]->is_success );
ok(
$b
[2]->message eq
"/test: Permission denied on server. (Delete)"
);
ok( !
$b
[3]->is_success );
ok(
$b
[3]->message eq
"Missing URL in request"
);
@b
= delete_urls(
@to_uris
);
ok(
@b
==
@to_uris
);
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok(
$b
[0]->is_success );
ok(
$b
[1]->is_success );
ok(
$b
[2]->is_success );
ok(
$b
[3]->is_success );
ok(
$b
[4]->is_success );
@b
= delete_urls(
@to_uris
);
ok(
@b
==
@to_uris
);
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok( !
$b
[0]->is_success );
ok( !
$b
[1]->is_success );
ok( !
$b
[2]->is_success );
ok( !
$b
[3]->is_success );
ok( !
$b
[4]->is_success );
ok( copy_url(
$from_uris
[4],
$to_uris
[4]) );
ok( move_url(
$to_uris
[4],
$to_uris
[0]) );
ok( !move_url(
$to_uris
[4],
$to_uris
[0]) );
ok( $@ =~ m?/t/file5.new: No such file or directory? );
ok( !copy_url(
' '
,
' '
) );
ok( $@ eq
'Missing GET URL'
);
ok( $@ eq
'Missing PUT URL'
);
ok( !copy_urls([], []) );
ok( $@ eq
'No non-empty GET URLs'
);
ok( $@ eq
'No non-empty PUT URLs'
);
@b
= delete_urls(
' '
);
ok(
$b
[0] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
'Missing URL in request'
);
@b
= get_urls(
' '
);
ok(
$b
[0] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
'Missing URL in request'
);
@b
= move_url(
' '
,
'file:/tmp/ '
);
ok( !
$b
[0] );
ok( $@ eq
'Missing GET URL'
);
@b
= move_url(
'/etc/passwd'
,
' '
);
ok( !
$b
[0] );
ok( $@ eq
'Missing PUT URL'
);
@b
= put_urls(
'test'
,
' '
);
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
'Missing URL in request'
);
@b
= copy_urls([
''
,
$from_uris
[0]], [
@to_uris
,
''
,
'file:/no/such/path/ZZZ/'
]);
ok(
@b
);
ok(
$b
[0] );
ok(
$b
[1] );
ok( !
$b
[0]->is_success );
ok(
$b
[0]->message eq
'Missing URL in request'
);
ok(
$b
[1]->is_success );
ok(
$b
[1]->{put_requests}[0]->is_success );
ok(
$b
[1]->{put_requests}[1]->is_success );
ok(
$b
[1]->{put_requests}[2]->is_success );
ok(
$b
[1]->{put_requests}[3]->is_success );
ok(
$b
[1]->{put_requests}[4]->is_success );
ok( !
$b
[1]->{put_requests}[5]->is_success );
ok(
$b
[1]->{put_requests}[5]->message eq
'Missing URL in request'
);
ok( !
$b
[1]->{put_requests}[6]->is_success );
ok(
$b
[1]->{put_requests}[6]->message eq
'No such file or directory'
);
@b
= get_urls(
@to_uris
);
ok(
@b
==
@from_files
);
ok(
$b
[0] );
ok(
$b
[1] );
ok(
$b
[2] );
ok(
$b
[3] );
ok(
$b
[4] );
ok(
$b
[0]->is_success and
$b
[0]->content eq
$a
[0]->content );
ok(
$b
[1]->is_success and
$b
[1]->content eq
$a
[0]->content );
ok(
$b
[2]->is_success and
$b
[2]->content eq
$a
[0]->content );
ok(
$b
[3]->is_success and
$b
[3]->content eq
$a
[0]->content );
ok(
$b
[4]->is_success and
$b
[4]->content eq
$a
[0]->content );
ok( !list_url );
ok(
@b
== 13 );
ok( $@ =~ m:File or directory `.this.path.should.not.exist' does not exist:i );
ok( !list_url(
$from_uris
[0]) );
ok( $@ =~ m:t.file1' is not a directory:i );
ok( $@ =
"Cannot chdir to `ZZZ'"
);
ok(
@b
== 5 );
my
$http_req
= HTTP::Request->new(
'DELETE'
,
$from_uris
[0]);
ok(
$http_req
and
$http_req
->method eq
'DELETE'
);
@b
= get_urls(
$http_req
);
ok(
@b
== 1);
ok(
$b
[0] and
$b
[0]->is_success and
length
(
$b
[0]->content) == 90 );
ok(
$http_req
and
$http_req
->method eq
'DELETE'
);
ok( -e
'file6'
);
ok( -s _ == 90 );
ok(
unlink
(
'file6'
) );
ok(
unlink
(
map
{
$_
->file }
@to_uris
) ==
@from_files
);
ok(
@b
== 8 );