Tests: Add a perl test for eml checksums #3235
authorChristian Kamm <mail@ckamm.de>
Wed, 25 Nov 2015 11:46:45 +0000 (12:46 +0100)
committerChristian Kamm <mail@ckamm.de>
Wed, 25 Nov 2015 11:48:24 +0000 (12:48 +0100)
csync/tests/ownCloud/ownCloud/Test.pm
csync/tests/ownCloud/t9.pl [new file with mode: 0755]

index 821ffbdf089499bd6d201b800b4cda37701ec0de..cd83ec4e63080819a337cb47bfee38dd927505c4 100644 (file)
@@ -66,7 +66,7 @@ our %config;
                   assertLocalDirs assertLocalAndRemoteDir glob_put put_to_dir
                   putToDirLWP localDir remoteDir localCleanup createLocalFile md5OfFile
                   remoteCleanup server initLocalDir initRemoteDir moveRemoteFile
-                  printInfo remoteFileId createShare removeShare assert
+                  printInfo remoteFileProp remoteFileId createShare removeShare assert
                   configValue testDirUrl getToFileLWP getToFileCurl);
 
 sub server
@@ -679,28 +679,38 @@ sub printInfo($)
   $infoCnt++;
 }
 
-sub remoteFileId($$)
+sub remoteFileProp($$)
 {
   my ($fromDir, $file) = @_;
   my $fromUrl = testDirUrl() . $fromDir;
-  my $id;
+  my $result;
 
   if( my $r = $d->propfind( -url => $fromUrl, -depth => 1 ) ) {
     if ( $r->is_collection ) {
       # print "Collection\n";
 
       foreach my $res ( $r->get_resourcelist->get_resources() ) {
-       my $filename = $res->get_property("rel_uri");
-       # print "OOOOOOOOOOOOOO $filename " . $res->get_property('id') . "\n";
-       if( $file eq $filename || $filename eq $file . "/" ) {
-         $id = $res->get_property('id') || "";
-       }
+        my $filename = $res->get_property("rel_uri");
+        # print "OOOOOOOOOOOOOO $filename " . $res->get_property('id') . "\n";
+        if( $file eq $filename || $filename eq $file . "/" ) {
+          $result = $res;
+        }
       }
     } else {
       # print "OOOOOOOOOOOOOOOOOOO " . $r->get_property("rel_uri");
-      $id = $r->get_property('id') || "";
+      $result = $r;
     }
   }
+  return $result;
+}
+
+sub remoteFileId($$)
+{
+  my ($fromDir, $file) = @_;
+  my $id;
+  if( my $res = remoteFileProp($fromDir, $file) ) {
+    $id = $res->get_property('id') || "";
+  }
   print "## ID of $file: $id\n";
   return $id;
 }
diff --git a/csync/tests/ownCloud/t9.pl b/csync/tests/ownCloud/t9.pl
new file mode 100755 (executable)
index 0000000..9c2fb44
--- /dev/null
@@ -0,0 +1,91 @@
+#!/usr/bin/perl
+#
+# Test script for the ownCloud module of csync.
+# This script requires a running ownCloud instance accessible via HTTP.
+# It does quite some fancy tests and asserts the results.
+#
+# Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+use lib ".";
+
+use File::Copy;
+use ownCloud::Test;
+
+use strict;
+
+print "Hello, this is t9, a tester for content checksums.\n";
+
+initTesting();
+
+printInfo( "Add some files to local");
+my $locDir = localDir();
+copy( "testfiles/test.txt", "$locDir/test.txt");
+copy( "testfiles/test.txt", "$locDir/test.eml");
+
+csync( );
+print "\nAssert local and remote dirs.\n";
+assertLocalAndRemoteDir( '', 0);
+
+# Get file properties before syncing again
+my $txtpropbefore = remoteFileProp("", "test.txt");
+my $emlpropbefore = remoteFileProp("", "test.eml");
+assert($txtpropbefore);
+assert($emlpropbefore);
+
+printInfo( "Touch local files");
+system( "touch $locDir/test.txt" );
+system( "touch $locDir/test.eml" );
+
+csync( );
+
+# Get file properties afterwards
+my $txtpropafter = remoteFileProp("", "test.txt");
+my $emlpropafter = remoteFileProp("", "test.eml");
+assert($txtpropafter);
+assert($emlpropafter);
+
+# The txt file is uploaded normally, etag and mtime differ
+assert($txtpropafter->get_property( "getetag" ) ne
+       $txtpropbefore->get_property( "getetag" ));
+assert($txtpropafter->get_property( "getlastmodified" ) ne
+       $txtpropbefore->get_property( "getlastmodified" ));
+# The eml was not uploaded, nothing differs
+assert($emlpropafter->get_property( "getetag" ) eq
+       $emlpropbefore->get_property( "getetag" ));
+assert($emlpropafter->get_property( "getlastmodified" ) eq
+       $emlpropbefore->get_property( "getlastmodified" ));
+
+printInfo( "Change content of eml file (but not size)");
+system( "sed -i -e 's/in/IN/' $locDir/test.eml" );
+
+csync( );
+
+# Get file properties afterwards
+my $emlpropchanged = remoteFileProp("", "test.eml");
+assert($emlpropchanged);
+assert($emlpropafter->get_property( "getetag" ) ne
+       $emlpropchanged->get_property( "getetag" ));
+assert($emlpropafter->get_property( "getlastmodified" ) ne
+       $emlpropchanged->get_property( "getlastmodified" ));
+
+# ==================================================================
+
+cleanup();
+
+# --
+