From d26215a49b5d850a2bff6e75cfef7a036f1da60d Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 26 Feb 2018 16:27:38 -0500 Subject: [PATCH] ceph-volume tests.util ensure behavior of new which utility Signed-off-by: Alfredo Deza --- .../ceph_volume/tests/util/test_system.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_system.py b/src/ceph-volume/ceph_volume/tests/util/test_system.py index a742de4804cef..690147cb29b30 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_system.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_system.py @@ -166,3 +166,29 @@ class TestIsBinary(object): def test_is_not_binary(self, tmpfile): binary_path = tmpfile(contents='asd\n\nlkjh0') assert system.is_binary(binary_path) is False + + +class TestWhich(object): + + def test_executable_exists_but_is_not_file(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: False) + monkeypatch.setattr(system.os.path, 'exists', lambda x: True) + assert system.which('exedir') == 'exedir' + + def test_executable_does_not_exist(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: False) + monkeypatch.setattr(system.os.path, 'exists', lambda x: False) + assert system.which('exedir') == 'exedir' + + def test_executable_exists_as_file(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: True) + monkeypatch.setattr(system.os.path, 'exists', lambda x: True) + assert system.which('ceph') == '/usr/local/bin/ceph' + + def test_warnings_when_executable_isnt_matched(self, monkeypatch, capsys): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: True) + monkeypatch.setattr(system.os.path, 'exists', lambda x: False) + system.which('exedir') + stdout, stderr = capsys.readouterr() + assert 'Absolute path not found for executable: exedir' in stdout + assert 'Ensure $PATH environment variable contains common executable locations' in stdout -- 2.39.5