Skip to content

Commit

Permalink
[tests] Move "snapshot album" to test-case class
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Dec 20, 2023
1 parent 9b04aa3 commit cf3618e
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions tests/test_base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,36 @@ struct BaseVM : public Test
});
}

void mock_named_snapshotting(std::vector<std::shared_ptr<MockSnapshot>>* snapshot_album = nullptr)
void mock_named_snapshotting()
{
EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _))
.WillRepeatedly(WithArg<0>([snapshot_album](const std::string& name) {
auto ret = std::make_shared<NiceMock<MockSnapshot>>();
EXPECT_CALL(*ret, get_name).WillRepeatedly(Return(name));
EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _)).WillRepeatedly(WithArg<0>([this](const std::string& name) {
auto ret = std::make_shared<NiceMock<MockSnapshot>>();
EXPECT_CALL(*ret, get_name).WillRepeatedly(Return(name));

if (snapshot_album)
snapshot_album->push_back(ret);
snapshot_album.push_back(ret);

return ret;
}));
return ret;
}));
}

void mock_parented_named_snapshotting(std::vector<std::shared_ptr<MockSnapshot>>* snapshot_album = nullptr)
void mock_parented_named_snapshotting()
{
EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _))
.WillRepeatedly(
WithArgs<0, 3>([this, snapshot_album](const std::string& name, std::shared_ptr<mp::Snapshot> parent) {
auto ret = std::make_shared<NiceMock<MockSnapshot>>();
EXPECT_CALL(*ret, get_parent()).WillRepeatedly(Return(parent));
EXPECT_CALL(*ret, get_name).WillRepeatedly(Return(name));
.WillRepeatedly(WithArgs<0, 3>([this](const std::string& name, std::shared_ptr<mp::Snapshot> parent) {
auto ret = std::make_shared<NiceMock<MockSnapshot>>();
EXPECT_CALL(*ret, get_parent()).WillRepeatedly(Return(parent));
EXPECT_CALL(*ret, get_name).WillRepeatedly(Return(name));

if (snapshot_album)
snapshot_album->push_back(ret);
snapshot_album.push_back(ret);

return ret;
}));
return ret;
}));
}

mpt::MockSSHTestFixture mock_ssh_test_fixture;
const mpt::DummyKeyProvider key_provider{"keeper of the seven keys"};
NiceMock<MockBaseVirtualMachine> vm{"mock-vm"};
std::vector<std::shared_ptr<MockSnapshot>> snapshot_album;
};

TEST_F(BaseVM, get_all_ipv4_works_when_ssh_throws_opening_a_session)
Expand Down Expand Up @@ -547,8 +544,7 @@ TEST_F(BaseVM, throwsOnRepeatedSnapshotName)

TEST_F(BaseVM, snapshotDeletionUpdatesParents)
{
std::vector<std::shared_ptr<MockSnapshot>> snapshot_album{};
mock_parented_named_snapshotting(&snapshot_album);
mock_parented_named_snapshotting();

const auto num_snapshots = 3;
const mp::VMSpecs specs{};
Expand All @@ -563,8 +559,7 @@ TEST_F(BaseVM, snapshotDeletionUpdatesParents)

TEST_F(BaseVM, providesChildrenNames)
{
std::vector<std::shared_ptr<MockSnapshot>> snapshot_album{};
mock_named_snapshotting(&snapshot_album);
mock_named_snapshotting();

const auto name_template = "s{}";
const auto num_snapshots = 5;
Expand Down

0 comments on commit cf3618e

Please sign in to comment.