Minor fixups.

This commit is contained in:
Klaas Freitag 2013-03-22 10:22:50 +01:00
parent abe53a8669
commit 8b229f6413

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# Test script for the ownCloud module of csync. # Test script for the ownCloud module of csync.
# This script requires a running ownCloud instance accessible via HTTP. # This script requires a running ownCloud instance accessible via HTTP.
# It does quite some fancy tests and asserts the results. # It does quite some fancy tests and asserts the results.
# #
@ -25,7 +25,7 @@ print "Hello, this is t1, a tester for csync with ownCloud.\n";
# user => "joe", # user => "joe",
# passwd => "XXXXXX", # passwd => "XXXXXX",
# url => "http://localhost/oc/files/webdav.php" # url => "http://localhost/oc/files/webdav.php"
my $owncloud = "http://localhost/oc/files/webdav.php/"; my $owncloud = "http://localhost/oc/files/webdav.php/";
my $user = "joe"; my $user = "joe";
my $passwd = 'XXXXX'; # Mind to be secure. my $passwd = 'XXXXX'; # Mind to be secure.
@ -52,7 +52,7 @@ sub remoteDir( $$ )
my ($d, $dir) = @_; my ($d, $dir) = @_;
my $url = $owncloud . $dir ; my $url = $owncloud . $dir ;
$d->open( $owncloud ); $d->open( $owncloud );
print $d->message . "\n"; print $d->message . "\n";
@ -81,7 +81,7 @@ sub remoteCleanup( $;$ )
$d->open( -url => $owncloud ); $d->open( -url => $owncloud );
print "Cleaning Remote!\n"; print "Cleaning Remote!\n";
my $re = $d->delete( $dir ); my $re = $d->delete( $dir );
if( $re == 0 ) { if( $re == 0 ) {
@ -108,7 +108,7 @@ sub csync( $$ )
$url =~ s#^http://##; # Remove the leading http:// $url =~ s#^http://##; # Remove the leading http://
$url = "owncloud://$user:$passwd@". $url . $remote; $url = "owncloud://$user:$passwd@". $url . $remote;
print "CSync URL: $url\n"; print "CSync URL: $url\n";
my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync $local $url"; my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync $local $url";
print "Starting: $cmd\n"; print "Starting: $cmd\n";
@ -116,7 +116,7 @@ sub csync( $$ )
} }
# #
# Check local directories if they have the same content. # Check local directories if they have the same content.
# #
sub assertLocalDirs( $$ ) sub assertLocalDirs( $$ )
{ {
@ -135,7 +135,7 @@ sub assertLocalDirs( $$ )
} }
# #
# Check if a local and a remote dir have the same content # Check if a local and a remote dir have the same content
# #
sub assertLocalAndRemoteDir( $$$ ) sub assertLocalAndRemoteDir( $$$ )
{ {
@ -145,7 +145,7 @@ sub assertLocalAndRemoteDir( $$$ )
if( my $r = $d->propfind( -url => $owncloud . $remote, -depth => 1 ) ) { if( my $r = $d->propfind( -url => $owncloud . $remote, -depth => 1 ) ) {
if( $r->is_collection ) { if( $r->is_collection ) {
print "\nXX" . $r->get_resourcelist->as_string ."\n"; print "\nXX" . $r->get_resourcelist->as_string ."\n";
foreach my $res ( $r->get_resourcelist->get_resources() ) { foreach my $res ( $r->get_resourcelist->get_resources() ) {
print "Checking " . $res-> get_uri()->as_string ."\n"; print "Checking " . $res-> get_uri()->as_string ."\n";
my $filename = $res->get_property("rel_uri"); my $filename = $res->get_property("rel_uri");
@ -156,12 +156,15 @@ sub assertLocalAndRemoteDir( $$$ )
my $remoteModTime = $res->get_property( "lastmodifiedepoch" ) ; my $remoteModTime = $res->get_property( "lastmodifiedepoch" ) ;
my @info = stat( "$local/$filename" ); my @info = stat( "$local/$filename" );
my $localModTime = $info[9]; my $localModTime = $info[9];
assert( $remoteModTime == $localModTime, "Modfied-Times differ: remote: $remoteModTime <-> local: $localModTime" ); assert( abs($remoteModTime - $localModTime) < 5, "Modfied-Times differ: remote: $remoteModTime <-> local: $localModTime" );
# check for the same file size # check for the same file size
my $localSize = $info[7]; my $localSize = $info[7];
my $remoteSize = $res->get_property( "getcontentlength" ); my $remoteSize = $res->get_property( "getcontentlength" );
assert( $localSize == $remoteSize ); if( $remoteSize ) { # directories do not have a contentlength
print "Local versus Remote size: $localSize <-> $remoteSize\n";
assert( $localSize == $remoteSize );
}
# remember the files seen on the server. # remember the files seen on the server.
$seen{$filename} = 1; $seen{$filename} = 1;
@ -169,17 +172,18 @@ sub assertLocalAndRemoteDir( $$$ )
} }
# Now loop over the local directory content and check if all files in the dir # Now loop over the local directory content and check if all files in the dir
# were seen on the server. # were seen on the server.
print "\n* Cross checking with local dir: \n";
print "\n* Cross checking with local dir: \n";
print Dumper( %seen );
opendir(my $dh, $local ) || die; opendir(my $dh, $local ) || die;
while( readdir $dh ) { while( readdir $dh ) {
next if( /^\.+$/ ); next if( /^\.+$/ );
assert( -e "$local/$_" ); assert( -e "$local/$_" );
assert( $seen{$_} == 1, "Filename only local, but not remte: $_\n" ); my $f = $seen{$_} || $seen{$_ . "/"};
assert( $f == 1, "Filename only local, but not remote: <$_>\n" );
} }
closedir $dh; closedir $dh;
} }
} }
@ -189,7 +193,7 @@ sub glob_put( $$$ )
my( $d, $globber, $target ) = @_; my( $d, $globber, $target ) = @_;
$d->open( $target ); $d->open( $target );
my @puts = bsd_glob( $globber ); my @puts = bsd_glob( $globber );
foreach my $lfile( @puts ) { foreach my $lfile( @puts ) {
if( $lfile =~ /.*\/(.+)$/g ) { if( $lfile =~ /.*\/(.+)$/g ) {