From: Rishabh Dave Date: Tue, 9 May 2023 12:32:17 +0000 (+0530) Subject: src/tests/mds: improve test coverage in TestMDSAuthCaps X-Git-Tag: v19.0.0~866^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=bfacee1e4087b097b77b0b6592faa59774b0ec4f;p=ceph.git src/tests/mds: improve test coverage in TestMDSAuthCaps 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 --- diff --git a/src/test/mds/TestMDSAuthCaps.cc b/src/test/mds/TestMDSAuthCaps.cc index 4a7ad0082dcb7..84abd16c9b09d 100644 --- a/src/test/mds/TestMDSAuthCaps.cc +++ b/src/test/mds/TestMDSAuthCaps.cc @@ -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",