summaryrefslogtreecommitdiffstats
path: root/src/test/mds
diff options
context:
space:
mode:
authorRishabh Dave <ridave@redhat.com>2023-05-09 14:32:17 +0200
committerRishabh Dave <ridave@redhat.com>2023-07-14 15:10:40 +0200
commitbfacee1e4087b097b77b0b6592faa59774b0ec4f (patch)
tree762ec608e6d254188141f3af22275771b679cdc7 /src/test/mds
parentsrc/tests/mds: add tests for all combinations of MDS caps (diff)
downloadceph-bfacee1e4087b097b77b0b6592faa59774b0ec4f.tar.xz
ceph-bfacee1e4087b097b77b0b6592faa59774b0ec4f.zip
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 <ridave@redhat.com>
Diffstat (limited to 'src/test/mds')
-rw-r--r--src/test/mds/TestMDSAuthCaps.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/mds/TestMDSAuthCaps.cc b/src/test/mds/TestMDSAuthCaps.cc
index 4a7ad0082dc..84abd16c9b0 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",