2011-02-25 14:55:15 +00:00
|
|
|
#!/usr/bin/lua
|
|
|
|
require("posix")
|
|
|
|
dofile("tests/testlib.lua")
|
|
|
|
|
|
|
|
cwriteln("****************************************************************")
|
|
|
|
cwriteln(" Testing excludes ")
|
|
|
|
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 = {
|
2015-10-14 12:23:37 +00:00
|
|
|
logfile = "]]..logfile..[[",
|
|
|
|
nodaemon = true,
|
2011-02-25 14:55:15 +00:00
|
|
|
delay = 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
sync {
|
2015-10-14 12:23:37 +00:00
|
|
|
default.rsync,
|
2011-02-25 14:55:15 +00:00
|
|
|
source = "]]..srcdir..[[",
|
|
|
|
target = "]]..trgdir..[[",
|
|
|
|
exclude = {
|
2015-10-14 12:23:37 +00:00
|
|
|
"erf",
|
2011-02-25 14:55:15 +00:00
|
|
|
"/eaf",
|
|
|
|
"erd/",
|
|
|
|
"/ead/",
|
|
|
|
},
|
|
|
|
}]]);
|
|
|
|
|
|
|
|
-- writes all files
|
2012-03-21 10:39:52 +00:00
|
|
|
local function writefiles()
|
2011-02-25 14:55:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
-- test if the filename exists, fails if this is different to expect
|
2012-03-21 10:39:52 +00:00
|
|
|
local function testfile(filename, expect)
|
2011-02-25 14:55:15 +00:00
|
|
|
local stat, err = posix.stat(filename)
|
|
|
|
if stat and not expect then
|
|
|
|
cwriteln("failure: ",filename," should be excluded");
|
|
|
|
os.exit(1);
|
|
|
|
end
|
|
|
|
if not stat and expect then
|
|
|
|
cwriteln("failure: ",filename," should not be excluded");
|
|
|
|
os.exit(1);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- test all files
|
2012-03-21 10:39:52 +00:00
|
|
|
local function testfiles()
|
2011-02-25 14:55:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'testing startup excludes' );
|
|
|
|
writefiles( );
|
|
|
|
cwriteln( 'starting Lsyncd' );
|
|
|
|
local pid = spawn( './lsyncd', cfgfile, '-log', 'all');
|
|
|
|
|
|
|
|
cwriteln( 'waiting for Lsyncd to start' );
|
|
|
|
posix.sleep( 3 )
|
|
|
|
cwriteln( 'testing excludes after startup' );
|
|
|
|
testfiles( );
|
|
|
|
cwriteln( 'ok, removing sources' );
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
if srcdir:sub( 1,4 ) ~= '/tmp'
|
|
|
|
then
|
2011-02-25 14:55:15 +00:00
|
|
|
-- just to make sure before rm -rf
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' );
|
|
|
|
os.exit( 1 );
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
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 );
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'writing files after startup' );
|
2012-10-07 18:48:09 +00:00
|
|
|
writefiles( );
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'waiting for Lsyncd to transmit changes' );
|
2012-10-07 18:48:09 +00:00
|
|
|
posix.sleep( 5 );
|
|
|
|
testfiles( );
|
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'killing started Lsyncd' );
|
2012-10-07 18:48:09 +00:00
|
|
|
posix.kill( pid );
|
|
|
|
local _, exitmsg, lexitcode = posix.wait( lpid );
|
2015-10-14 12:23:37 +00:00
|
|
|
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode );
|
2011-02-25 14:55:15 +00:00
|
|
|
|
2015-10-14 12:23:37 +00:00
|
|
|
if lexitcode == 143
|
|
|
|
then
|
2012-10-07 18:48:09 +00:00
|
|
|
cwriteln( "OK" );
|
|
|
|
os.exit( 0 );
|
|
|
|
else
|
|
|
|
os.exit( 1 );
|
2011-02-25 14:55:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO remove temp
|