]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm/tests: add test coverage for recursive_chown function 49799/head
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 19 Jan 2023 22:04:36 +0000 (17:04 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 19 Jan 2023 22:04:36 +0000 (17:04 -0500)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/tests/test_util_funcs.py

index a36dd922ea1555166adf6635496f00039cf44a34..a6c2396c17fa15b3be6ac55aa3adaa9220be8305 100644 (file)
@@ -270,3 +270,21 @@ class TestMoveFiles:
                 assert c.args[1:] == (0, 0)
         assert dst.is_file()
         assert not file1.exists()
+
+
+def test_recursive_chown(tmp_path):
+    d1 = tmp_path / "dir1"
+    d2 = d1 / "dir2"
+    f1 = d2 / "file1.txt"
+    d2.mkdir(parents=True)
+
+    with f1.open("w") as fh:
+        fh.write("low down\n")
+
+    with mock.patch("os.chown") as _chown:
+        _chown.return_value = None
+        _cephadm.recursive_chown(str(d1), uid=500, gid=500)
+    assert len(_chown.mock_calls) == 3
+    assert _chown.mock_calls[0].args == (str(d1), 500, 500)
+    assert _chown.mock_calls[1].args == (str(d2), 500, 500)
+    assert _chown.mock_calls[2].args == (str(f1), 500, 500)