]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: add test cases for EmptyResponder decorator
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 23 May 2022 19:47:49 +0000 (15:47 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 23 Aug 2022 17:01:45 +0000 (13:01 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/tests/test_object_format.py

index 6a1215fac38ec3d429f9649cb56c4fc7329d6c90..43b5ef971a0fbb74681115b926b36f535298e32a 100644 (file)
@@ -270,6 +270,21 @@ class DecoDemo:
             raise object_format.ErrorResponse(f"{name} bad")
         return 0, name, ""
 
+    @CLICommand("empty one", perm="rw")
+    @object_format.EmptyResponder()
+    def empty_one(self, name: str = "default") -> None:
+        # in real code, this would be making some sort of state change
+        # but we need to handle erors still
+        if name in ["pow"]:
+            raise object_format.ErrorResponse(name, return_value=-5)
+        return
+
+    @CLICommand("empty bad", perm="rw")
+    @object_format.EmptyResponder()
+    def empty_bad(self, name: str = "default") -> int:
+        # in real code, this would be making some sort of state change
+        return 5
+
 
 @pytest.mark.parametrize(
     "prefix, args, response",
@@ -413,6 +428,26 @@ class DecoDemo:
                 "zamboni bad",
             ),
         ),
+        # ---
+        (
+            "empty one",
+            {"name": "zucchini"},
+            (
+                0,
+                "",
+                "",
+            ),
+        ),
+        # ---
+        (
+            "empty one",
+            {"name": "pow"},
+            (
+                -5,
+                "",
+                "pow",
+            ),
+        ),
     ],
 )
 def test_cli_with_decorators(prefix, args, response):
@@ -447,3 +482,9 @@ def test_error_response():
     assert r[1] == ""
     assert "blat" in r[2]
     assert r[0] == e3.mgr_return_value()
+
+
+def test_empty_responder_return_check():
+    dd = DecoDemo()
+    with pytest.raises(ValueError):
+        CLICommand.COMMANDS["empty bad"].call(dd, {}, None)