adding filter to testsuite, removing #! from testsuite

This commit is contained in:
Axel Kittenberger 2018-03-09 13:05:45 +01:00
parent ff0f4fbd7a
commit 1094759975
9 changed files with 174 additions and 35 deletions

View File

@ -93,6 +93,7 @@ add_custom_target( tests
COMMAND echo " * have a passwordless ssh access to localhost"
COMMAND ${LUA_EXECUTABLE} tests/schedule.lua
COMMAND ${LUA_EXECUTABLE} tests/l4rsyncdata.lua
COMMAND ${LUA_EXECUTABLE} tests/filter-rsync.lua
COMMAND ${LUA_EXECUTABLE} tests/exclude-rsync.lua
COMMAND ${LUA_EXECUTABLE} tests/exclude-rsyncssh.lua
COMMAND ${LUA_EXECUTABLE} tests/churn-rsync.lua

View File

@ -1,4 +1,3 @@
#!/usr/bin/lua
-- a heavy duty test.
-- makes thousends of random changes to the source tree

View File

@ -1,6 +1,6 @@
#!/usr/bin/lua
-- a heavy duty test.
-- makes thousends of random changes to the source tree
require( 'posix' )
dofile( 'tests/testlib.lua' )

View File

@ -1,4 +1,3 @@
#!/usr/bin/lua
-- a heavy duty test.
-- makes thousends of random changes to the source tree

View File

@ -1,16 +1,15 @@
#!/usr/bin/lua
require("posix")
dofile("tests/testlib.lua")
require( 'posix' )
dofile( 'tests/testlib.lua' )
cwriteln('****************************************************************' )
cwriteln(' Testing excludes (rsync)' )
cwriteln('****************************************************************' )
cwriteln( '****************************************************************' )
cwriteln( ' Testing excludes (rsync)' )
cwriteln(' ****************************************************************' )
local tdir, srcdir, trgdir = mktemps( )
local logfile = tdir .. "log"
local cfgfile = tdir .. "config.lua"
local logfile = tdir .. 'log'
local cfgfile = tdir .. 'config.lua'
local range = 5
local log = {"-log", "all"}
local log = { '-log', 'all' }
writefile(cfgfile, [[
settings {
@ -34,15 +33,15 @@ sync {
-- writes all files
local function writefiles
( )
posix.mkdir( srcdir .. "d" )
writefile( srcdir .. "erf", "erf" )
writefile( srcdir .. "eaf", "erf" )
writefile( srcdir .. "erd", "erd" )
writefile( srcdir .. "ead", "ead" )
writefile( srcdir .. "d/erf", "erf" )
writefile( srcdir .. "d/eaf", "erf" )
writefile( srcdir .. "d/erd", "erd" )
writefile( srcdir .. "d/ead", "ead" )
posix.mkdir( srcdir .. 'd' )
writefile( srcdir .. 'erf', 'erf' )
writefile( srcdir .. 'eaf', 'erf' )
writefile( srcdir .. 'erd', 'erd' )
writefile( srcdir .. 'ead', 'ead' )
writefile( srcdir .. 'd/erf', 'erf' )
writefile( srcdir .. 'd/eaf', 'erf' )
writefile( srcdir .. 'd/erd', 'erd' )
writefile( srcdir .. 'd/ead', 'ead' )
end
--
@ -73,14 +72,14 @@ end
-- test all files
local function testfiles
( )
testfile( trgdir .. "erf", false )
testfile( trgdir .. "eaf", false )
testfile( trgdir .. "erd", true )
testfile( trgdir .. "ead", true )
testfile( trgdir .. "d/erf", false )
testfile( trgdir .. "d/eaf", true )
testfile( trgdir .. "d/erd", true )
testfile( trgdir .. "d/ead", true )
testfile( trgdir .. 'erf', false )
testfile( trgdir .. 'eaf', false )
testfile( trgdir .. 'erd', true )
testfile( trgdir .. 'ead', true )
testfile( trgdir .. 'd/erf', false )
testfile( trgdir .. 'd/eaf', true )
testfile( trgdir .. 'd/erd', true )
testfile( trgdir .. 'd/ead', true )
end
@ -144,8 +143,7 @@ cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode );
if exitcode == 143
then
cwriteln( "OK" )
cwriteln( 'OK' )
os.exit( 0 )
else
os.exit( 1 )

View File

@ -1,5 +1,3 @@
#!/usr/bin/lua
require( 'posix' )
dofile( 'tests/testlib.lua' )

146
tests/filter-rsync.lua Normal file
View File

@ -0,0 +1,146 @@
require( 'posix' )
dofile( 'tests/testlib.lua' )
cwriteln( '****************************************************************' )
cwriteln( ' Testing filters (rsync)' )
cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps( )
local logfile = tdir .. "log"
local cfgfile = tdir .. "config.lua"
local range = 5
local log = {"-log", "all"}
writefile(cfgfile, [[
settings {
logfile = ']]..logfile..[[',
nodaemon = true,
}
sync {
default.rsync,
source = ']]..srcdir..[[',
target = ']]..trgdir..[[',
delay = 3,
filter = {
'- /ab**',
'+ /a**',
'- /**',
},
}]])
-- writes all files
local function writefiles
( )
writefile( srcdir .. 'abc', 'abc' )
writefile( srcdir .. 'acc', 'acc' )
writefile( srcdir .. 'baa', 'baa' )
posix.mkdir( srcdir .. 'abx' )
writefile( srcdir .. 'abx/a', 'abxa' )
posix.mkdir( srcdir .. 'acx' )
writefile( srcdir .. 'acx/x', 'acxx' )
end
--
-- Tests if the filename exists
-- fails if this is different to expect.
--
local function testfile
(
filename,
expect
)
local stat, err = posix.stat( filename )
if stat and not expect
then
cwriteln( 'failure: ', filename, ' should be filtered')
os.exit( 1 )
end
if not stat and expect
then
cwriteln( 'failure: ', filename, ' should not be filtered' )
os.exit( 1 )
end
end
-- test all files
local function testfiles
( )
testfile( trgdir .. 'abc', false )
testfile( trgdir .. 'acc', true )
testfile( trgdir .. 'baa', false )
testfile( trgdir .. 'abx/a', false )
testfile( trgdir .. 'acx/x', true )
end
cwriteln( 'testing startup filters' )
writefiles( )
cwriteln( 'starting Lsyncd' )
local pid = spawn( './lsyncd', cfgfile, '-log', 'all' )
cwriteln( 'waiting for Lsyncd to start' )
posix.sleep( 3 )
cwriteln( 'testing filters after startup' )
testfiles( )
cwriteln( 'ok, removing sources' )
if srcdir:sub( 1,4 ) ~= '/tmp'
then
-- just to make sure before rm -rf
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' )
os.exit( 1 )
end
os.execute( 'rm -rf '..srcdir..'/*' )
cwriteln( 'waiting for Lsyncd to remove destination' )
posix.sleep( 5 )
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
if result ~= 'exit' or code ~= 0
then
cwriteln( 'fail, target directory not empty!' )
os.exit( 1 )
end
cwriteln( 'writing files after startup' )
writefiles( )
cwriteln( 'waiting for Lsyncd to transmit changes' )
posix.sleep( 5 )
testfiles( )
cwriteln( 'killing started Lsyncd' )
posix.kill( pid )
local _, exitmsg, exitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode );
if exitcode == 143
then
cwriteln( 'OK' )
os.exit( 0 )
else
os.exit( 1 )
end
-- TODO remove temp

View File

@ -1,4 +1,3 @@
#!/usr/bin/lua
require( 'posix' )
dofile( 'tests/testlib.lua' )

View File

@ -1,4 +1,3 @@
#!/usr/bin/lua
require( 'posix' )
dofile( 'tests/testlib.lua' )