From: John Mulligan Date: Thu, 19 Jan 2023 22:04:36 +0000 (-0500) Subject: cephadm/tests: add test coverage for recursive_chown function X-Git-Tag: v18.1.0~441^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35db5e8da6789ca940ffa402bd2360b648b2934e;p=ceph.git cephadm/tests: add test coverage for recursive_chown function Signed-off-by: John Mulligan --- diff --git a/src/cephadm/tests/test_util_funcs.py b/src/cephadm/tests/test_util_funcs.py index a36dd922ea15..a6c2396c17fa 100644 --- a/src/cephadm/tests/test_util_funcs.py +++ b/src/cephadm/tests/test_util_funcs.py @@ -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)