lsyncd/tests/exclude-rsyncssh.lua

120 lines
2.9 KiB
Lua
Raw Normal View History

2011-02-25 14:55:15 +00:00
#!/usr/bin/lua
2012-02-16 15:49:34 +00:00
require('posix')
dofile('tests/testlib.lua')
2011-02-25 14:55:15 +00:00
2012-02-16 15:49:34 +00:00
cwriteln('****************************************************************');
cwriteln(' Testing excludes');
cwriteln('****************************************************************');
cwriteln(' (this test needs passwordless ssh localhost access ');
cwriteln(' for current user)');
2011-02-25 14:55:15 +00:00
local tdir, srcdir, trgdir = mktemps()
2012-02-16 15:49:34 +00:00
local logfile = tdir .. 'log'
local cfgfile = tdir .. 'config.lua'
2011-02-25 14:55:15 +00:00
local range = 5
local log = {}
2012-02-16 15:49:34 +00:00
log = {'-log', 'all'}
2011-02-25 14:55:15 +00:00
writefile(cfgfile, [[
settings = {
2012-02-16 15:49:34 +00:00
logfile = ']]..logfile..[[',
2011-02-25 14:55:15 +00:00
nodaemon = true,
delay = 3,
}
sync {
default.rsyncssh,
2012-02-16 15:49:34 +00:00
host = 'localhost',
source = ']]..srcdir..[[',
targetdir = ']]..trgdir..[[',
2011-02-25 14:55:15 +00:00
exclude = {
2012-02-16 15:49:34 +00:00
'erf',
'/eaf',
'erd/',
'/ead/',
2011-02-25 14:55:15 +00:00
},
}]]);
-- writes all files
2012-02-16 15:49:34 +00:00
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');
2011-02-25 14:55:15 +00:00
end
-- test if the filename exists, fails if this is different to expect
2012-02-16 15:49:34 +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
2012-02-16 15:49:34 +00:00
cwriteln('failure: ',filename,' should be excluded');
2011-02-25 14:55:15 +00:00
os.exit(1);
end
if not stat and expect then
2012-02-16 15:49:34 +00:00
cwriteln('failure: ',filename,' should not be excluded');
2011-02-25 14:55:15 +00:00
os.exit(1);
end
end
-- test all files
2012-02-16 15:49:34 +00:00
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);
2011-02-25 14:55:15 +00:00
end
2012-02-16 15:49:34 +00:00
cwriteln('testing startup excludes');
2011-02-25 14:55:15 +00:00
writefiles();
2012-02-16 15:49:34 +00:00
cwriteln('starting Lsyncd');
local pid = spawn('./lsyncd', cfgfile, unpack(log));
cwriteln('waiting for Lsyncd to start');
posix.sleep(10)
cwriteln('testing excludes after startup');
2011-02-25 14:55:15 +00:00
testfiles();
2012-02-16 15:49:34 +00:00
cwriteln('ok, removing sources');
if srcdir:sub(1,4) ~= '/tmp' then
2011-02-25 14:55:15 +00:00
-- just to make sure before rm -rf
2012-02-16 15:49:34 +00:00
cwriteln('exist before drama, srcdir is "', srcdir, '"');
2011-02-25 14:55:15 +00:00
os.exit(1);
end
2012-02-16 15:49:34 +00:00
os.execute('rm -rf '..srcdir..'/*');
cwriteln('waiting for Lsyncd to remove destination');
2011-02-25 14:55:15 +00:00
posix.sleep(5);
2012-02-16 15:49:34 +00:00
if os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0 then
cwriteln('fail, target directory not empty!');
2011-02-25 14:55:15 +00:00
os.exit(1);
end
2012-02-16 15:49:34 +00:00
cwriteln('writing files after startup');
2011-02-25 14:55:15 +00:00
writefiles();
2012-02-16 15:49:34 +00:00
cwriteln('waiting for Lsyncd to transmit changes');
posix.sleep(15);
2011-02-25 14:55:15 +00:00
testfiles();
2012-02-16 15:49:34 +00:00
cwriteln('killing started Lsyncd');
2011-02-25 14:55:15 +00:00
posix.kill(pid);
local _, exitmsg, lexitcode = posix.wait(lpid);
2012-02-16 15:49:34 +00:00
cwriteln('Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode);
2011-02-25 14:55:15 +00:00
posix.sleep(1);
2012-10-07 18:48:09 +00:00
if lexitcode == 143 then
cwriteln( 'OK' );
os.exit( 0 );
else
os.exit( 1 );
2011-02-25 14:55:15 +00:00
end
-- TODO remove temp