Skip to content

Commit

Permalink
[qemu][unit test] simplified the unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeliao committed Aug 9, 2024
1 parent 32d4e30 commit 39fb3b2
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions tests/qemu/test_qemu_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,24 +507,15 @@ TEST_F(QemuBackend, forceShutdownSuspendDeletesSuspendImageAndOffState)
return std::move(mock_qemu_platform);
});

mpt::MockProcessFactory::Callback snapshot_list_callback = [](mpt::MockProcess* process) {
mpt::MockProcessFactory::Callback snapshot_list_suspend_tag_callback = [](mpt::MockProcess* process) {
if (process->program().contains("qemu-img") && process->arguments().contains("snapshot") &&
process->arguments().contains("-l"))
{
constexpr auto snapshot_list_output_stream =
R"(Snapshot list:
ID TAG VM SIZE DATE VM CLOCK ICOUNT
1 @suspend 0 B 2024-06-11 23:22:59 00:00:00.000 0)";

mp::ProcessState exit_state;
exit_state.exit_code = 0;
EXPECT_CALL(*process, execute(_)).WillOnce(Return(exit_state));

EXPECT_CALL(*process, read_all_standard_output())
.WillRepeatedly(Return(QByteArray{snapshot_list_output_stream}));
.WillOnce(Return(fake_snapshot_list_with_suspend_tag));
}
};
process_factory->register_callback(snapshot_list_callback);
process_factory->register_callback(snapshot_list_suspend_tag_callback);

logger_scope.mock_logger->screen_logs(mpl::Level::debug);
logger_scope.mock_logger->expect_log(mpl::Level::info, "Forcing shutdown");
Expand All @@ -534,7 +525,7 @@ TEST_F(QemuBackend, forceShutdownSuspendDeletesSuspendImageAndOffState)
mpt::StubVMStatusMonitor stub_monitor;
mp::QemuVirtualMachineFactory backend{data_dir.path()};

auto machine = backend.create_virtual_machine(default_description, key_provider, stub_monitor);
const auto machine = backend.create_virtual_machine(default_description, key_provider, stub_monitor);
machine->state = mp::VirtualMachine::State::suspended;
machine->shutdown(true);

Expand Down

0 comments on commit 39fb3b2

Please sign in to comment.