Skip to content

Commit

Permalink
[tests] Adapt LXD mount tests to instance_dir
Browse files Browse the repository at this point in the history
Account for instance directories in new tests, after rebasing.

Signed-off-by: sharder996 <[email protected]>
  • Loading branch information
ricab authored and sharder996 committed Jul 27, 2023
1 parent f8652cb commit b1ef49d
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tests/lxd/test_lxd_mount_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <multipass/path.h>
#include <multipass/utils.h>
#include <multipass/virtual_machine_description.h>
#include <multipass/vm_mount.h>
Expand All @@ -40,8 +42,9 @@ class MockLXDVirtualMachine : public mpt::MockVirtualMachineT<mp::LXDVirtualMach
public:
MockLXDVirtualMachine(const mp::VirtualMachineDescription& desc, mp::VMStatusMonitor& monitor,
mp::NetworkAccessManager* manager, const QUrl& base_url, const QString& bridge_name,
const QString& storage_pool)
: mpt::MockVirtualMachineT<mp::LXDVirtualMachine>{desc, monitor, manager, base_url, bridge_name, storage_pool}
const QString& storage_pool, const mp::Path& instance_dir)
: mpt::MockVirtualMachineT<mp::LXDVirtualMachine>{desc, monitor, manager, base_url,
bridge_name, storage_pool, instance_dir}
{
}
};
Expand Down Expand Up @@ -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:///[email protected]"};
Expand Down Expand Up @@ -108,7 +113,8 @@ struct LXDMountHandlerValidGidUidParameterTests : public LXDMountHandlerTestFixt
TEST_F(LXDMountHandlerTestFixture, startDoesNotThrowIfVMIsStopped)
{
NiceMock<MockLXDVirtualMachine> 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);

Expand All @@ -121,7 +127,8 @@ TEST_F(LXDMountHandlerTestFixture, startDoesNotThrowIfVMIsStopped)
TEST_F(LXDMountHandlerTestFixture, startThrowsIfVMIsRunning)
{
NiceMock<MockLXDVirtualMachine> 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));
Expand All @@ -134,7 +141,8 @@ TEST_F(LXDMountHandlerTestFixture, startThrowsIfVMIsRunning)
TEST_F(LXDMountHandlerTestFixture, stopDoesNotThrowIfVMIsStopped)
{
NiceMock<MockLXDVirtualMachine> 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)
Expand All @@ -149,7 +157,8 @@ TEST_F(LXDMountHandlerTestFixture, stopDoesNotThrowIfVMIsStopped)
TEST_F(LXDMountHandlerTestFixture, stopThrowsIfVMIsRunning)
{
NiceMock<MockLXDVirtualMachine> 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);

Expand All @@ -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};
Expand All @@ -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,
Expand Down

0 comments on commit b1ef49d

Please sign in to comment.