Skip to content

Commit 6dd30d2

Browse files
committed
[tests] Check handling of rename failure
1 parent 1fa9488 commit 6dd30d2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_base_virtual_machine.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -987,4 +987,20 @@ TEST_F(BaseVM, takeSnapshotRevertsHeadAndCount)
987987
EXPECT_EQ(new_snapshot->get_index(), 2); // snapshot count not increased by failed snapshot
988988
}
989989

990+
TEST_F(BaseVM, renameFailureIsReverted)
991+
{
992+
std::string current_name = "before";
993+
std::string attempted_name = "after";
994+
auto snapshot = std::make_shared<NiceMock<MockSnapshot>>();
995+
EXPECT_CALL(*snapshot, get_name()).WillRepeatedly(Return(current_name));
996+
EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _)).WillOnce(Return(snapshot));
997+
998+
vm.take_snapshot({}, current_name, "");
999+
1000+
EXPECT_CALL(*snapshot, set_name(Eq(attempted_name))).WillOnce(Throw(std::runtime_error{"intentional"}));
1001+
EXPECT_ANY_THROW(vm.rename_snapshot(current_name, attempted_name));
1002+
1003+
EXPECT_EQ(vm.get_snapshot(current_name).get(), snapshot.get());
1004+
}
1005+
9901006
} // namespace

0 commit comments

Comments
 (0)