]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: data_allocate_fraction: arg_validators tests
authorJonas Pfefferle <pepperjo@japf.ch>
Thu, 3 Jun 2021 08:32:55 +0000 (10:32 +0200)
committerAdam King <adking@redhat.com>
Thu, 21 Sep 2023 13:09:16 +0000 (09:09 -0400)
Add tests for argument validator. Check for Nan, <=0.0 and > 1.0

Signed-off-by: Jonas Pfefferle <pepperjo@japf.ch>
(cherry picked from commit adf8c178214e79dcc18b5d222b9db276b0d2f032)

Conflicts:
src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py

src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py

index 59ca12619b061b59441e51f400fbdaf0c1ae84f7..3babecf827302d3ace353c4fcdfb6d1b8e4efbe3 100644 (file)
@@ -336,3 +336,28 @@ class TestValidBatchDataDevice(object):
         )
         self.validator.zap = False
         assert self.validator('/dev/foo')
+
+class TestValidFraction(object):
+
+    def setup(self):
+        self.validator = arg_validators.ValidFraction()
+
+    def test_fraction_is_valid(self, fake_call):
+        result = self.validator('0.8')
+        assert result == 0.8
+
+    def test_fraction_is_nan(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('NaN')
+
+    def test_fraction_is_negative(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('-1.0')
+
+    def test_fraction_is_zero(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('0.0')
+
+    def test_fraction_is_greater_one(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('1.1')