Skip to content

Commit

Permalink
[tests] Check handling of rename failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Jan 5, 2024
1 parent 1fa9488 commit 6dd30d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,4 +987,20 @@ TEST_F(BaseVM, takeSnapshotRevertsHeadAndCount)
EXPECT_EQ(new_snapshot->get_index(), 2); // snapshot count not increased by failed snapshot
}

TEST_F(BaseVM, renameFailureIsReverted)
{
std::string current_name = "before";
std::string attempted_name = "after";
auto snapshot = std::make_shared<NiceMock<MockSnapshot>>();
EXPECT_CALL(*snapshot, get_name()).WillRepeatedly(Return(current_name));
EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _)).WillOnce(Return(snapshot));

vm.take_snapshot({}, current_name, "");

EXPECT_CALL(*snapshot, set_name(Eq(attempted_name))).WillOnce(Throw(std::runtime_error{"intentional"}));
EXPECT_ANY_THROW(vm.rename_snapshot(current_name, attempted_name));

EXPECT_EQ(vm.get_snapshot(current_name).get(), snapshot.get());
}

} // namespace

0 comments on commit 6dd30d2

Please sign in to comment.