]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/tests: test returning error status works as expected
authorDhairya Parmar <dparmar@redhat.com>
Wed, 13 Sep 2023 19:04:25 +0000 (00:34 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Wed, 31 Jan 2024 10:24:08 +0000 (15:54 +0530)
Fixes: https://tracker.ceph.com/issues/62641
Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
Signed-off-by: John Mulligan <jmulliga@redhat.com>
(cherry picked from commit 4d663e4e4484977fb90beeb05f67bc71215bddb3)

src/pybind/mgr/tests/test_object_format.py

index d2fd20870e7ac77489d95712d81e601463dc031e..2e674c69838cae2489b8eb7e5d0def744404ff2f 100644 (file)
@@ -115,12 +115,18 @@ def test_format_yaml(obj: Any, compatible: bool, yaml_val: str):
 
 
 class Retty:
-    def __init__(self, v) -> None:
+    def __init__(self, v, status="") -> None:
         self.value = v
+        self.status = status
 
     def mgr_return_value(self) -> int:
         return self.value
 
+    def mgr_status_value(self) -> str:
+        if self.status:
+            return self.status
+        return "NOPE"
+
 
 @pytest.mark.parametrize(
     "obj, ret",
@@ -139,6 +145,24 @@ def test_return_value(obj: Any, ret: int):
     assert rva.mgr_return_value() == ret
 
 
+@pytest.mark.parametrize(
+    "obj, ret",
+    [
+        ({}, ""),
+        ({"fish": "sticks"}, ""),
+        (-55, ""),
+        (Retty(0), "NOPE"),
+        (Retty(-55, "cake"), "cake"),
+        (Retty(-50, "pie"), "pie"),
+    ],
+)
+def test_return_status(obj: Any, ret: str):
+    rva = object_format.StatusValueAdapter(obj)
+    # a StatusValueAdapter instance meets the StatusValueProvider protocol.
+    assert object_format._is_status_value_provider(rva)
+    assert rva.mgr_status_value() == ret
+
+
 def test_valid_formats():
     ofa = object_format.ObjectFormatAdapter({"fred": "wilma"})
     vf = ofa.valid_formats()