]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fs-util: Add relative path chase_symlinks() tests
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 5 Dec 2022 10:15:58 +0000 (11:15 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Dec 2022 01:39:20 +0000 (10:39 +0900)
src/test/test-fs-util.c

index 4bf0a5daf8765c85d4fcf8b9389addf166cf8a8a..8c4b632ed037c9f394703b96ff5096e12756e547 100644 (file)
@@ -27,7 +27,7 @@
 static const char *arg_test_dir = NULL;
 
 TEST(chase_symlinks) {
-        _cleanup_free_ char *result = NULL;
+        _cleanup_free_ char *result = NULL, *pwd = NULL;
         _cleanup_close_ int pfd = -1;
         char *temp;
         const char *top, *p, *pslash, *q, *qslash;
@@ -245,6 +245,30 @@ TEST(chase_symlinks) {
         assert_se(path_equal(result, p));
         result = mfree(result);
 
+        /* Relative paths */
+
+        assert_se(safe_getcwd(&pwd) >= 0);
+
+        assert_se(chdir(temp) >= 0);
+
+        p = "this/is/a/relative/path";
+        r = chase_symlinks(p, NULL, CHASE_NONEXISTENT, &result, NULL);
+        assert_se(r == 0);
+
+        p = strjoina(temp, "/", p);
+        assert_se(path_equal(result, p));
+        result = mfree(result);
+
+        p = "this/is/a/relative/path";
+        r = chase_symlinks(p, temp, CHASE_NONEXISTENT, &result, NULL);
+        assert_se(r == 0);
+
+        p = strjoina(temp, "/", p);
+        assert_se(path_equal(result, p));
+        result = mfree(result);
+
+        assert_se(chdir(pwd) >= 0);
+
         /* Path which doesn't exist, but contains weird stuff */
 
         p = strjoina(temp, "/idontexist/..");