]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/tests/mds: improve test coverage in TestMDSAuthCaps 51317/head
authorRishabh Dave <ridave@redhat.com>
Tue, 9 May 2023 12:32:17 +0000 (18:02 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 14 Jul 2023 13:10:40 +0000 (18:40 +0530)
Currently we check if the right caps parse successfully and the wrong
caps fail to parse. Increase the test coverage by adding one more
tests -- dump the right caps in to a string after the parsing is
successfully and then re-parse the caps and check if re-parsed caps
dumps to the exact same string.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/test/mds/TestMDSAuthCaps.cc

index 4a7ad0082dcb7ecec6e71d805413be6e9f766707..84abd16c9b09d52eb4b46a009a45021af6e9f210 100644 (file)
@@ -100,6 +100,32 @@ TEST(MDSAuthCaps, ParseGood) {
   }
 }
 
+TEST(MDSAuthCaps, ParseDumpReparseCaps) {
+  for (auto str : parse_good) {
+    MDSAuthCaps cap1;
+    ASSERT_TRUE(cap1.parse(str, &cout));
+
+    std::cout << "Testing by parsing caps, dumping to string, reparsing "
+                "string and then redumping and checking strings from "
+                "first and second dumps: '" << str << "'" << std::endl;
+    // Convert cap object to string, reparse and check if converting again
+    // gives same string as before.
+    MDSAuthCaps cap2;
+    std::ostringstream cap1_ostream;
+    cap1_ostream << cap1;
+    string cap1_str = cap1_ostream.str();
+    // Removing "MDSAuthCaps[" from cap1_str
+    cap1_str.replace(0, 12, "");
+    // Removing "]" from cap1_str
+    cap1_str.replace(cap1_str.length() - 1, 1, "");
+    ASSERT_TRUE(cap2.parse(cap1_str, &cout));
+
+    std::ostringstream cap2_ostream;
+    cap2_ostream << cap2;
+    ASSERT_TRUE(cap1_ostream.str().compare(cap2_ostream.str()) == 0);
+  }
+}
+
 const char *parse_bad[] = {
   "allow r poolfoo",
   "allow r w",