From: Christian Kamm Date: Wed, 25 Nov 2015 11:46:45 +0000 (+0100) Subject: Tests: Add a perl test for eml checksums #3235 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1390^2~17 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1aa570326e7900efc0fd4a0fc88fd92fa818c159;p=nextcloud-desktop.git Tests: Add a perl test for eml checksums #3235 --- diff --git a/csync/tests/ownCloud/ownCloud/Test.pm b/csync/tests/ownCloud/ownCloud/Test.pm index 821ffbdf0..cd83ec4e6 100644 --- a/csync/tests/ownCloud/ownCloud/Test.pm +++ b/csync/tests/ownCloud/ownCloud/Test.pm @@ -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 index 000000000..9c2fb44ae --- /dev/null +++ b/csync/tests/ownCloud/t9.pl @@ -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 +# +# 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(); + +# -- +