Skip to content

Commit 52cd030

Browse files
authored
Merge pull request #1041 from aschnell/master
- extended testsuite
2 parents 09a10d3 + 2b38f34 commit 52cd030

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

testsuite/SystemInfo/lvs.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ check(const vector<string>& input, const vector<string>& output)
3636
}
3737

3838

39+
void
40+
check(const string& vg_name, const string& lv_name, const vector<string>& input, const vector<string>& output)
41+
{
42+
Mockup::set_mode(Mockup::Mode::PLAYBACK);
43+
Mockup::set_command({ LVS_BIN, "--reportformat", "json", "--config", "log { command_names = 0 prefix = \"\" }",
44+
"--units", "b", "--nosuffix", "--all", "--options lv_name,lv_uuid,vg_name,vg_uuid,lv_role,lv_attr,"
45+
"lv_size,origin_size,segtype,stripes,stripe_size,chunk_size,pool_lv,pool_lv_uuid,origin,origin_uuid,"
46+
"data_lv,data_lv_uuid,metadata_lv,metadata_lv_uuid", "--", vg_name + "/" + lv_name }, input);
47+
48+
CmdLvs cmd_lvs(vg_name, lv_name);
49+
50+
ostringstream parsed;
51+
parsed.setf(std::ios::boolalpha);
52+
parsed << cmd_lvs;
53+
54+
string lhs = parsed.str();
55+
string rhs = boost::join(output, "\n") + "\n";
56+
57+
BOOST_CHECK_EQUAL(lhs, rhs);
58+
}
59+
60+
3961
BOOST_AUTO_TEST_CASE(parse1)
4062
{
4163
vector<string> input = {
@@ -386,3 +408,25 @@ BOOST_AUTO_TEST_CASE(parse9)
386408

387409
check(input, output);
388410
}
411+
412+
413+
BOOST_AUTO_TEST_CASE(parse10)
414+
{
415+
vector<string> input = {
416+
" {",
417+
" \"report\": [",
418+
" {",
419+
" \"lv\": [",
420+
" {\"lv_name\":\"c\", \"lv_uuid\":\"gqnD48-ev4p-nCdM-EWEP-RAgW-TaDC-h9Hb13\", \"vg_name\":\"b\", \"vg_uuid\":\"GbcwxM-Px5E-Xs7u-dLhx-r7RU-4LG4-uGR6Ew\", \"lv_role\":\"public\", \"lv_attr\":\"-wi-a-----\", \"lv_size\":\"107369988096\", \"origin_size\":\"\", \"segtype\":\"linear\", \"stripes\":\"1\", \"stripe_size\":\"0\", \"chunk_size\":\"0\", \"pool_lv\":\"\", \"pool_lv_uuid\":\"\", \"origin\":\"\", \"origin_uuid\":\"\", \"data_lv\":\"\", \"data_lv_uuid\":\"\", \"metadata_lv\":\"\", \"metadata_lv_uuid\":\"\"}",
421+
" ]",
422+
" }",
423+
" ]",
424+
" }"
425+
};
426+
427+
vector<string> output = {
428+
"lv:{ lv-name:c lv-uuid:gqnD48-ev4p-nCdM-EWEP-RAgW-TaDC-h9Hb13 vg-name:b vg-uuid:GbcwxM-Px5E-Xs7u-dLhx-r7RU-4LG4-uGR6Ew lv-type:normal role:public active:true size:107369988096 segments:<stripes:1> }"
429+
};
430+
431+
check("b", "c", input, output);
432+
}

testsuite/SystemInfo/pvs.cc

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ check(const vector<string>& input, const vector<string>& output)
1919
{
2020
Mockup::set_mode(Mockup::Mode::PLAYBACK);
2121
Mockup::set_command({ PVS_BIN, "--reportformat", "json", "--config", "log { command_names = 0 prefix = \"\" }",
22-
"--units", "b", "--nosuffix", "--all", "--options", "pv_name,pv_uuid,vg_name,vg_uuid,pv_attr,pe_start" }
23-
, input);
22+
"--units", "b", "--nosuffix", "--all", "--options", "pv_name,pv_uuid,vg_name,vg_uuid,pv_attr,pe_start" },
23+
input);
2424

2525
CmdPvs cmd_pvs;
2626

@@ -35,6 +35,27 @@ check(const vector<string>& input, const vector<string>& output)
3535
}
3636

3737

38+
void
39+
check(const string& pv_name, const vector<string>& input, const vector<string>& output)
40+
{
41+
Mockup::set_mode(Mockup::Mode::PLAYBACK);
42+
Mockup::set_command({ PVS_BIN, "--reportformat", "json", "--config", "log { command_names = 0 prefix = \"\" }",
43+
"--units", "b", "--nosuffix", "--all", "--options", "pv_name,pv_uuid,vg_name,vg_uuid,pv_attr,pe_start",
44+
pv_name }, input);
45+
46+
CmdPvs cmd_pvs(pv_name);
47+
48+
ostringstream parsed;
49+
parsed.setf(std::ios::boolalpha);
50+
parsed << cmd_pvs;
51+
52+
string lhs = parsed.str();
53+
string rhs = boost::join(output, "\n") + "\n";
54+
55+
BOOST_CHECK_EQUAL(lhs, rhs);
56+
}
57+
58+
3859
BOOST_AUTO_TEST_CASE(parse1)
3960
{
4061
vector<string> input = {
@@ -57,6 +78,30 @@ BOOST_AUTO_TEST_CASE(parse1)
5778
}
5879

5980

81+
BOOST_AUTO_TEST_CASE(parse2)
82+
{
83+
// The device reported pv name can be different from the provided pv name.
84+
85+
vector<string> input = {
86+
" {",
87+
" \"report\": [",
88+
" {",
89+
" \"pv\": [",
90+
" {\"pv_name\":\"/dev/md127\", \"pv_uuid\":\"nA8nKb-VSgN-fRvo-pGqm-pRBl-MX3M-Hf2sjT\", \"vg_name\":\"\", \"vg_uuid\":\"\", \"pv_attr\":\"---\", \"pe_start\":\"1048576\"}",
91+
" ]",
92+
" }",
93+
" ]",
94+
" }"
95+
};
96+
97+
vector<string> output = {
98+
"pv:{ pv-name:/dev/md127 pv-uuid:nA8nKb-VSgN-fRvo-pGqm-pRBl-MX3M-Hf2sjT vg-name: vg-uuid: pe-start:1048576 }"
99+
};
100+
101+
check("/dev/md/a", input, output);
102+
}
103+
104+
60105
BOOST_AUTO_TEST_CASE(parse_missing)
61106
{
62107
vector<string> input = {

testsuite/SystemInfo/vgs.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ check(const vector<string>& input, const vector<string>& output)
3535
}
3636

3737

38+
void
39+
check(const string& vg_name, const vector<string>& input, const vector<string>& output)
40+
{
41+
Mockup::set_mode(Mockup::Mode::PLAYBACK);
42+
Mockup::set_command({ VGS_BIN, "--reportformat", "json", "--config", "log { command_names = 0 prefix = \"\" }",
43+
"--units", "b", "--nosuffix", "--options", "vg_name,vg_uuid,vg_attr,vg_extent_size,"
44+
"vg_extent_count,vg_free_count", "--", vg_name }, input);
45+
46+
CmdVgs cmd_vgs(vg_name);
47+
48+
ostringstream parsed;
49+
parsed.setf(std::ios::boolalpha);
50+
parsed << cmd_vgs;
51+
52+
string lhs = parsed.str();
53+
string rhs = boost::join(output, "\n") + "\n";
54+
55+
BOOST_CHECK_EQUAL(lhs, rhs);
56+
}
57+
58+
3859
BOOST_AUTO_TEST_CASE(parse1)
3960
{
4061
vector<string> input = {
@@ -55,3 +76,25 @@ BOOST_AUTO_TEST_CASE(parse1)
5576

5677
check(input, output);
5778
}
79+
80+
81+
BOOST_AUTO_TEST_CASE(parse2)
82+
{
83+
vector<string> input = {
84+
" {",
85+
" \"report\": [",
86+
" {",
87+
" \"vg\": [",
88+
" {\"vg_name\":\"b\", \"vg_uuid\":\"GbcwxM-Px5E-Xs7u-dLhx-r7RU-4LG4-uGR6Ew\", \"vg_attr\":\"wz--n-\", \"vg_extent_size\":\"4194304\", \"vg_extent_count\":\"25640\", \"vg_free_count\":\"25640\"}",
89+
" ]",
90+
" }",
91+
" ]",
92+
" }"
93+
};
94+
95+
vector<string> output = {
96+
"vg:{ vg-name:b vg-uuid:GbcwxM-Px5E-Xs7u-dLhx-r7RU-4LG4-uGR6Ew extent-size:4194304 extent-count:25640 free-extent-count:25640 }"
97+
};
98+
99+
check("b", input, output);
100+
}

0 commit comments

Comments
 (0)