From b1ef49d8b3ffccb77431e0f94a4d015e43017d27 Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Tue, 27 Jun 2023 12:50:29 +0100 Subject: [PATCH] [tests] Adapt LXD mount tests to instance_dir Account for instance directories in new tests, after rebasing. Signed-off-by: sharder996 --- tests/lxd/test_lxd_mount_handler.cpp | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/lxd/test_lxd_mount_handler.cpp b/tests/lxd/test_lxd_mount_handler.cpp index 8bd3efc103b..267041f26c1 100644 --- a/tests/lxd/test_lxd_mount_handler.cpp +++ b/tests/lxd/test_lxd_mount_handler.cpp @@ -22,9 +22,11 @@ #include "tests/mock_virtual_machine.h" #include "tests/stub_ssh_key_provider.h" #include "tests/stub_status_monitor.h" +#include "tests/temp_dir.h" #include "src/platform/backends/lxd/lxd_mount_handler.h" +#include #include #include #include @@ -40,8 +42,9 @@ class MockLXDVirtualMachine : public mpt::MockVirtualMachineT{desc, monitor, manager, base_url, bridge_name, storage_pool} + const QString& storage_pool, const mp::Path& instance_dir) + : mpt::MockVirtualMachineT{desc, monitor, manager, base_url, + bridge_name, storage_pool, instance_dir} { } }; @@ -73,6 +76,8 @@ struct LXDMountHandlerTestFixture : public testing::Test mpt::MockLogger::Scope logger_scope = mpt::MockLogger::inject(); + mpt::TempDir instance_dir; + const mpt::StubSSHKeyProvider key_provider; const mp::VMMount vm_mount{source_path, {}, {}, mp::VMMount::MountType::Native}; const QUrl base_url{"unix:///foo@1.0"}; @@ -108,7 +113,8 @@ struct LXDMountHandlerValidGidUidParameterTests : public LXDMountHandlerTestFixt TEST_F(LXDMountHandlerTestFixture, startDoesNotThrowIfVMIsStopped) { NiceMock lxd_vm{ - default_description, stub_monitor, &mock_network_access_manager, base_url, bridge_name, default_storage_pool}; + default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; mp::LXDMountHandler lxd_mount_handler(&mock_network_access_manager, &lxd_vm, &key_provider, target_path, vm_mount); @@ -121,7 +127,8 @@ TEST_F(LXDMountHandlerTestFixture, startDoesNotThrowIfVMIsStopped) TEST_F(LXDMountHandlerTestFixture, startThrowsIfVMIsRunning) { NiceMock lxd_vm{ - default_description, stub_monitor, &mock_network_access_manager, base_url, bridge_name, default_storage_pool}; + default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; mp::LXDMountHandler lxd_mount_handler(&mock_network_access_manager, &lxd_vm, &key_provider, target_path, vm_mount); EXPECT_CALL(lxd_vm, current_state).WillOnce(Return(multipass::VirtualMachine::State::running)); @@ -134,7 +141,8 @@ TEST_F(LXDMountHandlerTestFixture, startThrowsIfVMIsRunning) TEST_F(LXDMountHandlerTestFixture, stopDoesNotThrowIfVMIsStopped) { NiceMock lxd_vm{ - default_description, stub_monitor, &mock_network_access_manager, base_url, bridge_name, default_storage_pool}; + default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; mp::LXDMountHandler lxd_mount_handler(&mock_network_access_manager, &lxd_vm, &key_provider, target_path, vm_mount); EXPECT_CALL(lxd_vm, current_state) @@ -149,7 +157,8 @@ TEST_F(LXDMountHandlerTestFixture, stopDoesNotThrowIfVMIsStopped) TEST_F(LXDMountHandlerTestFixture, stopThrowsIfVMIsRunning) { NiceMock lxd_vm{ - default_description, stub_monitor, &mock_network_access_manager, base_url, bridge_name, default_storage_pool}; + default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; mp::LXDMountHandler lxd_mount_handler(&mock_network_access_manager, &lxd_vm, &key_provider, target_path, vm_mount); @@ -165,8 +174,8 @@ TEST_F(LXDMountHandlerTestFixture, stopThrowsIfVMIsRunning) TEST_P(LXDMountHandlerInvalidGidUidParameterTests, mountWithGidOrUid) { - mp::LXDVirtualMachine lxd_vm{default_description, stub_monitor, &mock_network_access_manager, base_url, - bridge_name, default_storage_pool}; + mp::LXDVirtualMachine lxd_vm{default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; const auto& [host_gid, instance_gid, host_uid, instance_uid] = GetParam(); const mp::VMMount vm_mount{ source_path, {{host_gid, instance_gid}}, {{host_uid, instance_uid}}, mp::VMMount::MountType::Native}; @@ -182,8 +191,8 @@ INSTANTIATE_TEST_SUITE_P(mountWithGidOrUidInstantiation, LXDMountHandlerInvalidG TEST_P(LXDMountHandlerValidGidUidParameterTests, mountWithGidOrUid) { - mp::LXDVirtualMachine lxd_vm{default_description, stub_monitor, &mock_network_access_manager, base_url, - bridge_name, default_storage_pool}; + mp::LXDVirtualMachine lxd_vm{default_description, stub_monitor, &mock_network_access_manager, base_url, + bridge_name, default_storage_pool, instance_dir.path()}; const auto& [host_gid, host_uid] = GetParam(); const int default_instance_id = -1; const mp::VMMount vm_mount{source_path,