2012-02-28 15:27:00 +04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
2013-03-22 13:22:50 +04:00
|
|
|
# Test script for the ownCloud module of csync.
|
2012-02-28 15:27:00 +04:00
|
|
|
# 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>
|
|
|
|
#
|
|
|
|
|
2012-08-23 18:57:04 +04:00
|
|
|
use lib ".";
|
|
|
|
|
2012-02-28 15:27:00 +04:00
|
|
|
use Carp::Assert;
|
|
|
|
use File::Copy;
|
2013-05-15 13:15:50 +04:00
|
|
|
use ownCloud::Test;
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
print "Hello, this is t1, a tester for csync with ownCloud.\n";
|
|
|
|
|
2013-05-15 13:15:50 +04:00
|
|
|
initTesting();
|
2013-05-08 20:39:21 +04:00
|
|
|
|
2012-08-23 18:57:04 +04:00
|
|
|
print "Copy some files to the remote location\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
createRemoteDir( "remoteToLocal1" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl1" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl1/rtl11" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl2" );
|
2013-11-05 21:08:02 +04:00
|
|
|
createRemoteDir( "remoteToLocal1/rtl4" );
|
2012-02-28 15:27:00 +04:00
|
|
|
|
2013-05-15 13:15:50 +04:00
|
|
|
glob_put( 'toremote1/*', "remoteToLocal1/" );
|
|
|
|
glob_put( 'toremote1/rtl1/*', "remoteToLocal1/rtl1/" );
|
|
|
|
glob_put( 'toremote1/rtl1/rtl11/*', "remoteToLocal1/rtl1/rtl11/" );
|
|
|
|
glob_put( 'toremote1/rtl2/*', "remoteToLocal1/rtl2/" );
|
2013-11-05 21:08:02 +04:00
|
|
|
glob_put( 'toremote1/rtl4/*', "remoteToLocal1/rtl4/" );
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
# call csync, sync local t1 to remote t1
|
2013-05-15 13:15:50 +04:00
|
|
|
csync();
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
# Check if the files from toremote1 are now in t1/remoteToLocal1
|
2012-03-30 17:48:45 +04:00
|
|
|
# they should have taken the way via the ownCloud.
|
2012-08-23 18:57:04 +04:00
|
|
|
print "Assert the local file copy\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
assertLocalDirs( 'toremote1', localDir().'remoteToLocal1' );
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
# Check if the synced files from ownCloud have the same timestamp as the local ones.
|
2013-05-15 13:15:50 +04:00
|
|
|
print "\nNow assert remote 'toremote1' with local " . localDir() . " :\n";
|
|
|
|
assertLocalAndRemoteDir( 'remoteToLocal1', 0);
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
# remove a local file.
|
2012-08-23 18:57:04 +04:00
|
|
|
print "\nRemove a local file\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
unlink( localDir() . 'remoteToLocal1/kernelcrash.txt' );
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( 'remoteToLocal1', 0);
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
# add local files to a new dir1
|
2012-08-23 18:57:04 +04:00
|
|
|
print "\nAdd some more files to local:\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
my $locDir = localDir() . 'fromLocal1';
|
2012-02-28 15:27:00 +04:00
|
|
|
|
|
|
|
mkdir( $locDir );
|
|
|
|
assert( -d $locDir );
|
|
|
|
foreach my $file ( <./tolocal1/*> ) {
|
|
|
|
print "Copying $file to $locDir\n";
|
|
|
|
copy( $file, $locDir );
|
|
|
|
}
|
2013-05-15 13:15:50 +04:00
|
|
|
csync( );
|
2012-08-23 18:57:04 +04:00
|
|
|
print "\nAssert local and remote dirs.\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
assertLocalAndRemoteDir( 'fromLocal1', 0);
|
2012-02-28 15:27:00 +04:00
|
|
|
|
2012-03-30 17:48:45 +04:00
|
|
|
# move a local file
|
2012-08-23 18:57:04 +04:00
|
|
|
print "\nMove a file locally.\n";
|
2012-03-30 17:48:45 +04:00
|
|
|
move( "$locDir/kramer.jpg", "$locDir/oldtimer.jpg" );
|
2013-05-15 13:15:50 +04:00
|
|
|
csync( );
|
|
|
|
assertLocalAndRemoteDir( 'fromLocal1', 0);
|
2012-03-30 17:48:45 +04:00
|
|
|
|
2012-08-23 18:57:04 +04:00
|
|
|
# move a local directory.
|
|
|
|
print "\nMove a local directory.\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
move( localDir() . 'remoteToLocal1/rtl1', localDir(). 'remoteToLocal1/rtlX');
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( 'fromLocal1', 0);
|
2012-08-23 18:57:04 +04:00
|
|
|
|
|
|
|
# remove a local dir
|
|
|
|
print "\nRemove a local directory.\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
localCleanup( localDir() . 'remoteToLocal1/rtlX' );
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( 'fromLocal1', 0);
|
2013-05-08 20:39:21 +04:00
|
|
|
|
|
|
|
# create a false conflict, only the mtimes are changed, by content are equal.
|
|
|
|
print "\nCreate a false conflict.\n";
|
2013-05-15 13:15:50 +04:00
|
|
|
my $srcFile = 'toremote1/kernelcrash.txt';
|
|
|
|
put_to_dir( $srcFile, 'remoteToLocal1' );
|
|
|
|
system( "sleep 2 && touch $srcFile" );
|
|
|
|
csync( );
|
|
|
|
assertLocalAndRemoteDir( 'fromLocal1', 0);
|
2013-05-08 20:39:21 +04:00
|
|
|
|
|
|
|
# create a true conflict.
|
|
|
|
print "\nCreate a conflict.\n";
|
|
|
|
system( "echo \"This is more stuff\" >> /tmp/kernelcrash.txt" );
|
2013-05-15 13:15:50 +04:00
|
|
|
put_to_dir( '/tmp/kernelcrash.txt', 'remoteToLocal1' );
|
|
|
|
system( "sleep 2 && touch $srcFile" );
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( 'remoteToLocal1', 1);
|
2013-05-14 19:46:35 +04:00
|
|
|
|
2013-05-08 20:39:21 +04:00
|
|
|
# ==================================================================
|
2012-08-23 18:57:04 +04:00
|
|
|
|
2013-05-15 13:15:50 +04:00
|
|
|
cleanup();
|
2012-02-28 15:27:00 +04:00
|
|
|
|
2013-05-15 13:15:50 +04:00
|
|
|
# --
|
2012-02-28 15:27:00 +04:00
|
|
|
|