From c9a3b6af88b361665f662c15cdd4967167ac61f6 Mon Sep 17 00:00:00 2001 From: Scott Harder Date: Wed, 14 Aug 2024 10:44:01 -0700 Subject: [PATCH] [tests] refine qemu platform tests --- .../qemu/linux/test_qemu_platform_detail.cpp | 3 ++- tests/qemu/test_qemu_backend.cpp | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/qemu/linux/test_qemu_platform_detail.cpp b/tests/qemu/linux/test_qemu_platform_detail.cpp index 6ede824126..f66aeb4323 100644 --- a/tests/qemu/linux/test_qemu_platform_detail.cpp +++ b/tests/qemu/linux/test_qemu_platform_detail.cpp @@ -240,5 +240,6 @@ TEST_F(QemuPlatformDetail, CreateBridgeWithCallsExpectedMethods) mp::QemuPlatformDetail qemu_platform_detail{data_dir.path()}; - qemu_platform_detail.create_bridge_with(mp::NetworkInterfaceInfo{"en0", "ethernet", "", {}, true}); + EXPECT_EQ(qemu_platform_detail.create_bridge_with(mp::NetworkInterfaceInfo{"en0", "ethernet", "", {}, true}), + "br-en0"); } diff --git a/tests/qemu/test_qemu_backend.cpp b/tests/qemu/test_qemu_backend.cpp index cdbe43fbad..153431b387 100644 --- a/tests/qemu/test_qemu_backend.cpp +++ b/tests/qemu/test_qemu_backend.cpp @@ -802,24 +802,28 @@ TEST_F(QemuBackend, createsQemuSnapshotsFromJsonFile) EXPECT_EQ(snapshot->get_parent(), parent); } -TEST_F(QemuBackend, networks_does_not_throw) +TEST_F(QemuBackend, networks_returns_supported_networks) { + ON_CALL(*mock_qemu_platform, is_network_supported(_)).WillByDefault(Return(true)); + EXPECT_CALL(*mock_qemu_platform_factory, make_qemu_platform(_)).WillOnce([this](auto...) { return std::move(mock_qemu_platform); }); mp::QemuVirtualMachineFactory backend{data_dir.path()}; + const std::map networks{ + {"lxdbr0", {"lxdbr0", "bridge", "gobbledygook"}}, + {"mpbr0", {"mpbr0", "bridge", "gobbledygook"}}, + {"virbr0", {"virbr0", "bridge", "gobbledygook"}}, + {"mpqemubr0", {"mpqemubr0", "bridge", "gobbledygook"}}, + {"enxe4b97a832426", {"enxe4b97a832426", "ethernet", "gobbledygook"}}}; + auto [mock_platform, guard] = mpt::MockPlatform::inject(); - EXPECT_CALL(*mock_platform, get_network_interfaces_info) - .WillOnce(Return(std::map{ - {"lxdbr0", {"lxdbr0", "bridge", "gobbledygook"}}, - {"mpbr0", {"mpbr0", "bridge", "gobbledygook"}}, - {"virbr0", {"virbr0", "bridge", "gobbledygook"}}, - {"mpqemubr0", {"mpqemubr0", "bridge", "gobbledygook"}}, - {"enxe4b97a832426", {"enxe4b97a832426", "ethernet", "gobbledygook"}}})); + EXPECT_CALL(*mock_platform, get_network_interfaces_info).WillOnce(Return(networks)); - EXPECT_NO_THROW(backend.networks()); + auto supported_nets = backend.networks(); + EXPECT_EQ(supported_nets.size(), networks.size()); } TEST_F(QemuBackend, remove_resources_for_calls_qemu_platform) @@ -915,7 +919,7 @@ TEST_F(QemuBackend, createBridgeWithChecksWithQemuPlatform) mp::QemuVirtualMachineFactory backend{data_dir.path()}; std::vector extra_interfaces{{"eth1", "52:54:00:00:00:00", true}}; - backend.prepare_networking(extra_interfaces); + EXPECT_NO_THROW(backend.prepare_networking(extra_interfaces)); } TEST(QemuPlatform, base_qemu_platform_returns_expected_values)