mirror of
https://github.com/troglobit/libite.git
synced 2026-11-06 15:50:57 +00:00
test: finalize rsync unit test to reproduce bugs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
eb3bb94cfa
commit
e36ac8f462
1 file changed
+65
-35
+65
-35
@@ -48,52 +48,82 @@ void setup_test(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_tree(char *heading, char *dir)
|
int check_dir_to_dir(void)
|
||||||
{
|
{
|
||||||
if (verbose) {
|
int rc = 0;
|
||||||
if (heading)
|
|
||||||
puts(heading);
|
rc += rsync(SRC, DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||||
|
rc += systemf("diff -rq %s %s", SRC, DST);
|
||||||
|
systemf("rm -rf %s/*", DST);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_file_to_file(void)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
touch(SRC "foo.txt");
|
||||||
|
PRINT("SRC ==========================\n");
|
||||||
|
if (verbose) system("ls -l " SRC);
|
||||||
|
rc += rsync(SRC "foo.txt", DST "foo.txt", LITE_FOPT_KEEP_MTIME, NULL);
|
||||||
|
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt")) {
|
||||||
|
PRINT("No dst file or it's a directory\n");
|
||||||
|
rc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Fixme, add code to list tree, nftw() possibly
|
PRINT("DST ==========================\n");
|
||||||
|
if (verbose) system("ls -l " DST);
|
||||||
|
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_file_to_dir(void)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
touch(SRC "foo.txt");
|
||||||
|
PRINT("SRC ==========================\n");
|
||||||
|
if (verbose) system("ls -l " SRC);
|
||||||
|
rc += rsync(SRC "foo.txt", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||||
|
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt"))
|
||||||
|
rc++;
|
||||||
|
PRINT("DST ==========================\n");
|
||||||
|
if (verbose) system("ls -l " DST);
|
||||||
|
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_file_to_nodir(void)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
touch(SRC "foo.txt");
|
||||||
|
PRINT("SRC ==========================\n");
|
||||||
|
if (verbose) system("ls -l " SRC);
|
||||||
|
system("rm -rf " DST);
|
||||||
|
rc += rsync(SRC "foo.txt", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||||
|
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt"))
|
||||||
|
rc++;
|
||||||
|
PRINT("DST ==========================\n");
|
||||||
|
if (verbose) system("ls -l " DST);
|
||||||
|
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_test(void)
|
int run_test(void)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
#if 0
|
|
||||||
setup_test();
|
setup_test();
|
||||||
check_tree("Before:", BASE);
|
|
||||||
|
|
||||||
result += rsync(SRC, DST, 0, NULL);
|
result += test(check_dir_to_dir(), "Verifying src/ -> dst/");
|
||||||
check_tree("After:", BASE);
|
result += test(check_file_to_file(), "Verifying src/foo.txt -> dst/foo.txt");
|
||||||
cleanup_test();
|
result += test(check_file_to_dir(), "Verifying src/foo.txt -> dst/");
|
||||||
#endif
|
result += test(check_file_to_nodir(),"Verifying src/foo.txt -> dst/ (non-existing target dir)");
|
||||||
|
|
||||||
setup_test();
|
|
||||||
sleep(1);
|
|
||||||
result += rsync(BASE "src", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
|
||||||
check_tree("Only partial rsync of src <-- No slash!", BASE);
|
|
||||||
#if 0
|
|
||||||
cleanup_test();
|
|
||||||
setup_test();
|
|
||||||
result += rsync(BASE "src/sub1", BASE "dst", 0, NULL);
|
|
||||||
check_tree("Only partial rsync of src/sub1 <-- No slashes!!", BASE);
|
|
||||||
|
|
||||||
cleanup_test();
|
|
||||||
setup_test();
|
|
||||||
result += rsync(BASE "src/sub1/", DST, 0, NULL);
|
|
||||||
check_tree("Only partial rsync of src/sub1/", BASE);
|
|
||||||
|
|
||||||
cleanup_test();
|
|
||||||
setup_test();
|
|
||||||
result += rsync(BASE "src/sub1", DST, 0, NULL);
|
|
||||||
check_tree("Only partial rsync of src/sub1 <-- No slash!", BASE);
|
|
||||||
|
|
||||||
result += rsync("/etc", "/var/tmp", 0, NULL);
|
|
||||||
check_tree("Real life test:", "/var/tmp");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user