X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fceph-volume%2Fceph_volume%2Ftests%2Fdevices%2Fsimple%2Ftest_scan.py;fp=src%2Fceph%2Fsrc%2Fceph-volume%2Fceph_volume%2Ftests%2Fdevices%2Fsimple%2Ftest_scan.py;h=d68fe63cb65b883316662ebde11b364ce1b5c1c9;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py b/src/ceph/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py new file mode 100644 index 0000000..d68fe63 --- /dev/null +++ b/src/ceph/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py @@ -0,0 +1,52 @@ +import os +import pytest +from ceph_volume.devices.simple import scan + + +class TestScan(object): + + def test_main_spits_help_with_no_arguments(self, capsys): + scan.Scan([]).main() + stdout, stderr = capsys.readouterr() + assert 'Scan an OSD directory for files' in stdout + + +class TestGetContents(object): + + def test_multiple_lines_are_left_as_is(self, tmpfile): + magic_file = tmpfile(contents='first\nsecond\n') + scanner = scan.Scan([]) + assert scanner.get_contents(magic_file) == 'first\nsecond\n' + + def test_extra_whitespace_gets_removed(self, tmpfile): + magic_file = tmpfile(contents='first ') + scanner = scan.Scan([]) + assert scanner.get_contents(magic_file) == 'first' + + def test_single_newline_values_are_trimmed(self, tmpfile): + magic_file = tmpfile(contents='first\n') + scanner = scan.Scan([]) + assert scanner.get_contents(magic_file) == 'first' + + +class TestEtcPath(object): + + def test_directory_is_valid(self, tmpdir): + path = str(tmpdir) + scanner = scan.Scan([]) + scanner._etc_path = path + assert scanner.etc_path == path + + def test_directory_does_not_exist_gets_created(self, tmpdir): + path = os.path.join(str(tmpdir), 'subdir') + scanner = scan.Scan([]) + scanner._etc_path = path + assert scanner.etc_path == path + assert os.path.isdir(path) + + def test_complains_when_file(self, tmpfile): + path = tmpfile() + scanner = scan.Scan([]) + scanner._etc_path = path + with pytest.raises(RuntimeError): + scanner.etc_path