Skip to content

Commit

Permalink
libc: resolve_path: add symlink renaming test
Browse files Browse the repository at this point in the history
JIRA: DTR-75
  • Loading branch information
nalajcie committed Jun 24, 2021
1 parent cf91f19 commit e063593
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libc/resolve_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,36 @@ TEST(resolve_path, symlink_loop)
}


/* check if mv symlink chages name of the symlink and not the target file */
TEST(resolve_path, symlink_rename)
{
/* CWD = prefix */
TEST_ASSERT_EQUAL_INT(0, chdir(prefix));

unlink("symlink_old");
unlink("symlink_new");
unlink("real_file");

create_file("real_file", file_contents);

if (symlink("real_file", "symlink_old") < 0)
TEST_FAIL_MESSAGE(strerror(errno));

check_file_contents(file_contents, "symlink_old");

if (rename("symlink_old", "symlink_new") < 0)
TEST_FAIL_MESSAGE(strerror(errno));

check_file_contents(file_contents, "real_file");
check_file_open_errno(ENOENT, "symlink_old");
check_file_contents(file_contents, "symlink_new");

/* cleanup - WARN: if failed - not reached */
TEST_ASSERT_EQUAL_INT(0, unlink("symlink_new"));
TEST_ASSERT_EQUAL_INT(0, unlink("real_file"));
}


TEST_GROUP_RUNNER(resolve_path)
{
RUN_TEST_CASE(resolve_path, canonicalize_abs_simple);
Expand All @@ -454,4 +484,5 @@ TEST_GROUP_RUNNER(resolve_path)
RUN_TEST_CASE(resolve_path, symlink_create_file);
RUN_TEST_CASE(resolve_path, symlink_dir);
RUN_TEST_CASE(resolve_path, symlink_loop);
RUN_TEST_CASE(resolve_path, symlink_rename);
}

0 comments on commit e063593

Please sign in to comment.