[metadata_checker_t] add damage_should_include() method.

This commit is contained in:
Joe Thornber 2013-05-02 12:51:55 +01:00
parent c976fc3d6c
commit 5a231a7db0

View File

@ -306,6 +306,15 @@ namespace {
return *dev_checker_; return *dev_checker_;
} }
void damage_should_include(damage_list_ptr damage, missing_device_details const &md) {
ASSERT_THAT(damage->size(), Gt(0u));
damage_visitor_mock v;
EXPECT_CALL(v, visit(Matcher<missing_device_details const &>(Eq(md))));
(*damage->begin())->visit(v);
}
private: private:
auto_ptr<device_checker> dev_checker_; auto_ptr<device_checker> dev_checker_;
}; };
@ -344,18 +353,17 @@ TEST_F(DeviceCheckerTests, fails_with_corrupt_root)
zero_block(devices_root()); zero_block(devices_root());
damage_list_ptr damage = dev_checker().check(); damage_list_ptr damage = dev_checker().check();
ASSERT_THAT(damage->size(), Eq(1u)); damage_should_include(damage, missing_device_details(range64()));
damage_visitor_mock v;
EXPECT_CALL(v, visit(Matcher<missing_device_details const &>(Eq(missing_device_details(range64())))));
(*damage->begin())->visit(v);
} }
TEST_F(DeviceCheckerTests, damaging_some_btree_nodes_results_in_the_correct_devices_being_flagged_as_missing) TEST_F(DeviceCheckerTests, damaging_some_btree_nodes_results_in_the_correct_devices_being_flagged_as_missing)
{ {
metadata_builder &b = get_builder(); metadata_builder &b = get_builder();
// FIXME: We should optimise the restorer so it clones the mapping
// tree for zero mapping devices, rather than allocating a new one.
// It would save allocating a heap of blocks, and more importantly
// make these tests run much faster.
for (unsigned i = 0; i < 2000; i++) for (unsigned i = 0; i < 2000; i++)
b.add_device(i); b.add_device(i);
@ -370,12 +378,7 @@ TEST_F(DeviceCheckerTests, damaging_some_btree_nodes_results_in_the_correct_devi
zero_block(n.b); zero_block(n.b);
damage_list_ptr damage = dev_checker().check(); damage_list_ptr damage = dev_checker().check();
ASSERT_THAT(damage->size(), Eq(1u)); damage_should_include(damage, missing_device_details(range64(n.keys)));
damage_visitor_mock v;
EXPECT_CALL(v, visit(Matcher<missing_device_details const &>(Eq(missing_device_details(range64(n.keys))))));
(*damage->begin())->visit(v);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------