From 93ee5a9a1187b6682b0d44182c892840aa07a4cf Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 24 Nov 2023 20:57:52 +0000 Subject: [PATCH] [tests] Check that BaseVM counts current snapshots --- tests/test_base_virtual_machine.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_base_virtual_machine.cpp b/tests/test_base_virtual_machine.cpp index c489f12c503..bc6b9aee1ac 100644 --- a/tests/test_base_virtual_machine.cpp +++ b/tests/test_base_virtual_machine.cpp @@ -317,4 +317,33 @@ TEST(BaseVMSnapshots, deletesSnapshots) vm.delete_snapshot("s1"); EXPECT_EQ(vm.get_num_snapshots(), 0); } + +TEST(BaseVMSnapshots, countsCurrentSnapshots) +{ + const mp::VMSpecs specs{}; + MockBaseVirtualMachine vm{"mock-vm"}; + EXPECT_EQ(vm.get_num_snapshots(), 0); + + auto snapshot = std::make_shared(); + EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _)).WillRepeatedly(Return(snapshot)); + EXPECT_CALL(*snapshot, capture).Times(AnyNumber()); + EXPECT_CALL(*snapshot, erase).Times(AnyNumber()); + + vm.take_snapshot(specs, "s1", ""); + EXPECT_EQ(vm.get_num_snapshots(), 1); + + vm.take_snapshot(specs, "s2", ""); + vm.take_snapshot(specs, "s3", ""); + EXPECT_EQ(vm.get_num_snapshots(), 3); + + vm.delete_snapshot("s1"); + EXPECT_EQ(vm.get_num_snapshots(), 2); + + vm.delete_snapshot("s2"); + vm.delete_snapshot("s3"); + EXPECT_EQ(vm.get_num_snapshots(), 0); + + vm.take_snapshot(specs, "s4", ""); + EXPECT_EQ(vm.get_num_snapshots(), 1); +} } // namespace