Переглянути джерело

tests: Never stumble over an already existing test share dir.

Klaas Freitag 11 роки тому
батько
коміт
c3f8e099f4
2 змінених файлів з 35 додано та 5 видалено
  1. 28 2
      csync/tests/ownCloud/ownCloud/Test.pm
  2. 7 3
      csync/tests/ownCloud/t5.pl

+ 28 - 2
csync/tests/ownCloud/ownCloud/Test.pm

@@ -61,7 +61,7 @@ our $infoCnt = 1;
 our %config;
 
 @ISA        = qw(Exporter);
-@EXPORT     = qw( initTesting createRemoteDir createLocalDir cleanup csync
+@EXPORT     = qw( initTesting createRemoteDir removeRemoteDir createLocalDir cleanup csync
                   assertLocalDirs assertLocalAndRemoteDir glob_put put_to_dir 
                   putToDirLWP localDir remoteDir localCleanup createLocalFile md5OfFile
                   remoteCleanup server initLocalDir initRemoteDir moveRemoteFile
@@ -180,6 +180,32 @@ sub initLocalDir
   mkdir ($localDir, 0777 );
 }
 
+sub removeRemoteDir($;$)
+{
+    my ($dir, $optionsRef) = @_;
+
+    my $url = testDirUrl() . $dir;
+
+    if( $optionsRef && $optionsRef->{user} && $optionsRef->{passwd} ) {
+	$d->credentials( -url=> $owncloud, -realm=>"ownCloud",
+			 -user=> $optionsRef->{user},
+			 -pass=> $optionsRef->{passwd} );
+	if( $optionsRef->{url} ) {
+	    $url = $optionsRef->{url} . $dir;
+	}
+    }
+
+    $d->open( $owncloud );
+    print $d->message . "\n";
+
+    my $re = $d->delete( $url );
+    if( $re == 0 ) {
+	print "Failed to remove directory <$url>:" . $d->message() ."\n";
+    }
+  
+    return $re;
+}
+
 sub createRemoteDir(;$$)
 {
     my ($dir, $optionsRef) = @_;
@@ -200,7 +226,7 @@ sub createRemoteDir(;$$)
 
     my $re = $d->mkcol( $url );
     if( $re == 0 ) {
-	print "Failed to create directory <$url>: $d->message() \n";
+	print "Failed to create directory <$url>: " . $d->message() ."\n";
 	exit 1;
     }
     $d->open( $url );

+ 7 - 3
csync/tests/ownCloud/t5.pl

@@ -37,6 +37,13 @@ initTesting();
 csync();
 
 my $share_dir = "share_source";
+my $sharee = { user   => configValue('share_user'),
+               passwd => configValue('share_passwd'),
+	       url    => server() };
+
+# first remove a possibly left over share dir.
+printInfo( "Remove possibly left over share dir" );
+removeRemoteDir( $share_dir, $sharee );
 
 printInfo( "Create a share." );
 my $shareId = createShare( $share_dir, 31 );
@@ -44,9 +51,6 @@ print "Created share with id <$shareId>\n";
 
 assert( $shareId > 0 );
 
-my $sharee = { user   => configValue('share_user'),
-               passwd => configValue('share_passwd'),
-	       url    => server() };
 # put a couple of files into the shared directory in the sharer account
 glob_put( 'sharing/*', $share_dir, $sharee);