Skip to content

Commit 0e9b9cd

Browse files
committed
[tests][qemu] Tests for management_ipv4().
1 parent 803e214 commit 0e9b9cd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/qemu/test_qemu_backend.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,37 @@ TEST_F(QemuBackend, ssh_hostname_returns_expected_value)
530530
EXPECT_EQ(machine.VirtualMachine::ssh_hostname(), expected_ip);
531531
}
532532

533+
TEST_F(QemuBackend, gets_management_ip)
534+
{
535+
mpt::StubVMStatusMonitor stub_monitor;
536+
const std::string expected_ip{"10.10.0.35"};
537+
NiceMock<mpt::MockDNSMasqServer> mock_dnsmasq_server{data_dir.path(), bridge_name, subnet};
538+
539+
ON_CALL(mock_dnsmasq_server, get_ip_for(_)).WillByDefault([&expected_ip](auto...) {
540+
return mp::optional<mp::IPAddress>{expected_ip};
541+
});
542+
543+
mp::QemuVirtualMachine machine{default_description, tap_device, mock_dnsmasq_server, stub_monitor};
544+
machine.start();
545+
machine.state = mp::VirtualMachine::State::running;
546+
547+
EXPECT_EQ(machine.management_ipv4(), expected_ip);
548+
}
549+
550+
TEST_F(QemuBackend, fails_to_get_management_ip_if_dnsmasq_does_not_return_an_ip)
551+
{
552+
mpt::StubVMStatusMonitor stub_monitor;
553+
NiceMock<mpt::MockDNSMasqServer> mock_dnsmasq_server{data_dir.path(), bridge_name, subnet};
554+
555+
ON_CALL(mock_dnsmasq_server, get_ip_for(_)).WillByDefault([](auto...) { return mp::optional<mp::IPAddress>{}; });
556+
557+
mp::QemuVirtualMachine machine{default_description, tap_device, mock_dnsmasq_server, stub_monitor};
558+
machine.start();
559+
machine.state = mp::VirtualMachine::State::running;
560+
561+
EXPECT_EQ(machine.management_ipv4(), "UNKNOWN");
562+
}
563+
533564
TEST_F(QemuBackend, ssh_hostname_timeout_throws_and_sets_unknown_state)
534565
{
535566
mpt::StubVMStatusMonitor stub_monitor;

0 commit comments

Comments
 (0)