Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snapshots] Unit tests #3256

Closed
wants to merge 139 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
f0fd629
[tests] Add file to test base snapshots
ricab Oct 16, 2023
a25bc2a
[tests] Test BaseSnapshot adopts given name
ricab Nov 15, 2023
4d49b4f
[tests] Test a couple other snapshot properties
ricab Oct 16, 2023
180ee91
[tests] Test that BaseSnapshot rejects empty name
ricab Oct 16, 2023
81385ee
[tests] Check that snapshots adopt given specs
ricab Oct 16, 2023
5502ceb
[tests] Check snapshots index
ricab Oct 16, 2023
abe717c
[tests] Check parent properties
ricab Oct 16, 2023
ced651a
[tests] Check snapshot timestamp
ricab Oct 16, 2023
089e58b
[tests] Check required state for snapshots
ricab Nov 15, 2023
993355e
[tests] Check invalid number of cores in snapshot
ricab Nov 15, 2023
9059a35
[tests] Verify invalid memory and disk in snapshot
ricab Nov 15, 2023
47d8312
[tests] Reorganize includes slightly
ricab Nov 15, 2023
6bb202e
[tests] Check snapshot reconstruction from JSON
ricab Nov 15, 2023
84e2bfa
[tests] Fix dangling temporary path in MockVM
ricab Nov 15, 2023
5bca2e1
[tests] Check snapshot name from JSON
ricab Nov 15, 2023
d29b24d
[tests] Check snapshot comment from JSON
ricab Nov 15, 2023
3c5b0bd
[tests] Use camelCase names in base snapshot tests
ricab Nov 21, 2023
ca9f600
[tests] Check snapshot parent from JSON
ricab Nov 21, 2023
fa811d3
[tests] Remove no-op moves
ricab Nov 21, 2023
7508682
[tests] Add a few missing consts
ricab Nov 21, 2023
388121d
[tests] Check snapshot index from JSON
ricab Nov 22, 2023
2603808
[tests] Check snapshot timestamp from JSON
ricab Nov 22, 2023
3dc41ab
[tests] Check snapshot cores from JSON
ricab Nov 22, 2023
8ddf57c
[tests] Check snapshot mem from JSON
ricab Nov 22, 2023
0bcd54f
[tests] Check snapshot disk from JSON
ricab Nov 22, 2023
bd1c1f8
[tests] Check snapshot state from JSON
ricab Nov 22, 2023
e6cf46b
[tests] Check snapshot metadata from JSON
ricab Nov 22, 2023
f3e5b3d
[tests] Check snapshot mounts from JSON
ricab Nov 22, 2023
ca85ff8
[snapshot] Fix assert when loading from disk
ricab Nov 22, 2023
52993d0
[tests] Check refused non-positive snapshot index
ricab Nov 22, 2023
8b3f823
[tests] Check refused snapshot index over max
ricab Nov 22, 2023
0b1c7fb
[tests] Check snapshot persistence on edition
ricab Nov 22, 2023
44cb34b
[tests] Check snapshot setters
ricab Nov 22, 2023
a3aa61c
[tests] Check capture persists snapshots
ricab Nov 23, 2023
bedbadb
[tests] Check operations that delegate to impl
ricab Nov 23, 2023
48b6ccb
[tests] Verify that erase deletes snapshot file
ricab Nov 23, 2023
bbd86a7
[tests] Check erase throws if unable to move file
ricab Nov 23, 2023
b5b3c60
[tests] Check rollback on failure to erase
ricab Nov 23, 2023
1682f42
[tests] Cover mounts in JSON-based snapshot tests
ricab Nov 23, 2023
5d7356a
[tests] Check handling of inability to open file
ricab Nov 23, 2023
f5e9414
[tests] Test snapshot handling of bad JSON
ricab Nov 23, 2023
c5a12d8
[snapshot] Fix wrong order in error message
ricab Nov 23, 2023
c73385d
[tests] Check handling of missing snapshot parent
ricab Nov 23, 2023
e893695
[tests] Refactor test-snapshot file path
ricab Nov 23, 2023
eef6012
[tests] Name file-path symbols consistently
ricab Nov 23, 2023
ad0a29f
[tests] Silence benign mock warnings
ricab Nov 23, 2023
34d13fa
[tests] Add macros to delegate mock calls on base
ricab Nov 24, 2023
ea37faa
[tests] Implement `MockBaseVirtualMachine`
ricab Dec 19, 2023
307a348
[tests] Implement `MockSnapshot`
ricab Nov 24, 2023
489c227
[tests] Check that BaseVM takes/deletes snapshots
ricab Nov 24, 2023
17859ce
[tests] Check that BaseVM counts current snapshots
ricab Nov 24, 2023
efecaee
[tests] Check that BaseVM tracks snapshot totals
ricab Nov 24, 2023
972a02f
[tests] Move BaseVM-snapshot tests to common suite
ricab Dec 7, 2023
475fe1c
[tests] Check that BaseVM provides a snapshot view
ricab Dec 7, 2023
4af7df9
[tests] Remove repeated method mocking
ricab Dec 7, 2023
16f4ea0
[tests] Mock missing const method overloads
ricab Dec 7, 2023
386eb49
[tests] Check BaseVM provides snapshot by name
ricab Dec 7, 2023
f32a2b2
[tests] Use nice snapshot mocks in BaseVM tests
ricab Dec 7, 2023
43e2f27
[tests] Check BaseVM provides snapshot by index
ricab Dec 7, 2023
51bea06
[tests] Fix mock method signature
ricab Dec 12, 2023
73fbae5
[tests] Verify handling of missing snapshot index
ricab Dec 14, 2023
6ae9773
[tests] Refactor mocking for indexed snapshotting
ricab Dec 14, 2023
12cbd6f
[tests] Verify handling of missing snapshot names
ricab Dec 14, 2023
27c7db9
[tests] Slight renaming
ricab Dec 14, 2023
37d3a42
[tests] Verify repeated snapshot names are refused
ricab Dec 14, 2023
fb5fcf2
[tests] Verify snapshot deletion updates parents
ricab Dec 14, 2023
f743a6d
[tests] Avoid unnecessary casts
ricab Dec 18, 2023
45ce49c
[tests] Avoid repeated calls
ricab Dec 18, 2023
eeb6b06
[tests] Check that VM can get snapshots' children
ricab Dec 19, 2023
58f5a12
[tests] Move "snapshot album" to test-case class
ricab Dec 19, 2023
df524da
[tests] Check renaming of snapshots by VM
ricab Jan 5, 2024
7c69061
[tests] Check deletion of missing snapshot throws
ricab Dec 22, 2023
2095fbb
[tests] Confirm logging of head snapshot
ricab Dec 22, 2023
b23321a
[tests] Check that BaseVM restores snapshots
ricab Jan 5, 2024
8d4169a
[tests] Check restored snapshot used as parent
ricab Dec 22, 2023
bd3a917
[tests] Fix dangling reference in stub VM
ricab Dec 22, 2023
b1bbb34
[tests] Take unique_ptrs by value in stub VMs
ricab Dec 22, 2023
b3e735c
[tests] Fix using mp-namespace shortcut in header
ricab Dec 22, 2023
f3f9f79
[tests] Check BaseVM refuses to take snapshot
ricab Dec 22, 2023
55cba85
[vm] Use smallcase "snapshots" feature name
ricab Dec 22, 2023
7be366c
[tests] Fix a couple of test names
ricab Jan 3, 2024
7324ceb
[tests] Check generated snapshot names
ricab Jan 3, 2024
8995999
[tests] Check loading of snapshot-count
ricab Jan 3, 2024
d51b2ef
[tests] Verify loading of padded counts
ricab Jan 3, 2024
2638588
[tests] Use a single helper to mock snapshotting
ricab Jan 3, 2024
d08698c
[tests] Extract verification of test params
ricab Jan 3, 2024
40b1972
[tests] Verify loading of head index
ricab Jan 3, 2024
f21fd9b
[tests] Check loading of snapshots by VM
ricab Jan 4, 2024
1708cf9
[tests] Check missing generic-snapshot-info files
ricab Jan 4, 2024
bceaeb8
[tests] Fix platform-dependent regex
ricab Jan 5, 2024
d92cd2c
[tests] Check handling of repeated snapshot names
ricab Jan 5, 2024
8b76be7
[test] Check parent rollback on erase failure
ricab Jan 5, 2024
2f8464f
[tests] Check head rollback on deletion
ricab Jan 5, 2024
dd0cb9f
[tests] Check null head after capture failure
ricab Jan 5, 2024
53dca77
[tests] Check rollback to previous head on failure
ricab Jan 5, 2024
1b100d5
[tests] Check handling of rename failure
ricab Jan 5, 2024
d77e0af
[tests] Refactor platform-dependent regex elements
ricab Jan 8, 2024
4081c0f
[tests] Check persistence of generic snapshot info
ricab Jan 8, 2024
5344418
[tests] Fix include order
ricab Jan 8, 2024
991fbd6
[tests] Check new info files removed on failure
ricab Jan 8, 2024
17af3e3
[tests] Factor out a couple of constants
ricab Jan 8, 2024
c51882f
[tests] Reorder test-case class contents slightly
ricab Jan 8, 2024
7fd4c84
[tests] Factor out a couple common vars in tests
ricab Jan 8, 2024
bdbdc86
[tests] Further refactor common snapshot file vars
ricab Jan 8, 2024
23313a3
[tests] Check rollback of existing info files
ricab Jan 8, 2024
c050833
[tests] Check head persisted on restore
ricab Jan 8, 2024
acb8fcb
[tests] Refactor derivation of regex matcher
ricab Jan 8, 2024
99a1e07
[tests] Refactor platform dependent constants
ricab Jan 8, 2024
c3b6d13
[tests] Fix gmock warning
ricab Jan 9, 2024
97a8e5b
[tests] Test rollback of failed snapshot restore
ricab Jan 9, 2024
e8d1364
[tests] Add file to test QemuSnapshot
ricab Jan 9, 2024
8f19a06
[tests] Add a PublicQemuSnapshot class for testing
ricab Jan 9, 2024
afa6282
[tests] Extract MockSnapshot
ricab Jan 9, 2024
18c6122
[tests] Check init of base fields in QemuSnapshot
ricab Jan 9, 2024
4328bbd
[tests] Check init of QemuSnapshot from JSON
ricab Jan 9, 2024
3fa389b
[tests] Extract vm specs for reuse
ricab Jan 10, 2024
e54b44c
[tests] Check capture of QEMU snapshots
ricab Jan 10, 2024
657d98b
[tests] Refactor bits for reuse
ricab Jan 10, 2024
3a86969
[tests] Check QemuSnapshot capture throws
ricab Jan 10, 2024
99b6ff6
[tests] Refactor common test components
ricab Jan 10, 2024
be5fe2e
[snapshot] Be robust to missing file on erase
ricab Jan 10, 2024
1dbdeae
[tests] Check erasure of QEMU snapshots
ricab Jan 10, 2024
738344f
[tests] Check erase on missing QEMU snapshot
ricab Jan 10, 2024
d31af84
[tests] Check applying QEMU snapshots
ricab Jan 10, 2024
5e84c28
[tests] Check rollback on failure to apply
ricab Jan 10, 2024
1712a0e
[tests] Check throw on unsupported snapshots
ricab Jan 12, 2024
cb3f61d
[tests] Improve test for trim_end utility
ricab Jan 12, 2024
31056e6
[test] Check trim_begin utility
ricab Jan 12, 2024
4612ec9
[test] Check trim utility
ricab Jan 12, 2024
0a790c4
[tests] Refactor sample string out of trim tests
ricab Jan 12, 2024
7aab0c6
[tests] Check creation of QEMU-specific snapshots
ricab Jan 12, 2024
32c063f
[tests] Use a mock vm to test QEMU snapshots
ricab Jan 15, 2024
9020fa2
[tests] Snapshot creation from file by QEMU VM
ricab Jan 15, 2024
fe4f7f1
[tests] Compare shared_ptr directly where possible
ricab Jan 15, 2024
1cdd044
[tests] Verify support for snapshots in QEMU
ricab Jan 15, 2024
1665ae4
[tests] Check writeJson creates parent directory
ricab Jan 15, 2024
7ec8b45
[tests] Check handling of failure to create dir
ricab Jan 15, 2024
0f5ff28
[tests] Check full sequence to write JSON
ricab Jan 15, 2024
f6bfb48
[tests] Check remaining failure cases of writeJson
ricab Jan 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/platform/backends/shared/base_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ QJsonObject read_snapshot_json(const QString& filename)

if (const auto json = QJsonDocument::fromJson(data, &parse_error).object(); parse_error.error)
throw std::runtime_error{fmt::format("Could not parse snapshot JSON; error: {}; file: {}",
file.fileName(),
parse_error.errorString())};
parse_error.errorString(),
file.fileName())};
else if (json.isEmpty())
throw std::runtime_error{fmt::format("Empty snapshot JSON: {}", file.fileName())};
else
Expand Down Expand Up @@ -124,7 +124,6 @@ mp::BaseSnapshot::BaseSnapshot(const std::string& name, // NOLINT(modernize-p
storage_dir{storage_dir},
captured{captured}
{
assert(index > 0 && "snapshot indices need to start at 1");
using St = VirtualMachine::State;
if (state != St::off && state != St::stopped)
throw std::runtime_error{fmt::format("Unsupported VM state in snapshot: {}", static_cast<int>(state))};
Expand Down Expand Up @@ -161,6 +160,7 @@ mp::BaseSnapshot::BaseSnapshot(const std::string& name,
vm.instance_directory(),
/*captured=*/false}
{
assert(index > 0 && "snapshot indices need to start at 1");
}

mp::BaseSnapshot::BaseSnapshot(const QString& filename, VirtualMachine& vm)
Expand Down Expand Up @@ -238,7 +238,7 @@ auto mp::BaseSnapshot::erase_helper()
auto deleting_filepath = tmp_dir->filePath(snapshot_filename);

QFile snapshot_file{snapshot_filepath};
if (!MP_FILEOPS.rename(snapshot_file, deleting_filepath))
if (!MP_FILEOPS.rename(snapshot_file, deleting_filepath) && snapshot_file.exists())
throw std::runtime_error{
fmt::format("Failed to move snapshot file to temporary destination: {}", deleting_filepath)};

Expand Down
4 changes: 2 additions & 2 deletions src/platform/backends/shared/base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ std::shared_ptr<Snapshot> BaseVirtualMachine::make_specific_snapshot(const std::
const VMSpecs& /*specs*/,
std::shared_ptr<Snapshot> /*parent*/)
{
throw NotImplementedOnThisBackendException{"Snapshots"};
throw NotImplementedOnThisBackendException{"snapshots"};
}

std::shared_ptr<Snapshot> BaseVirtualMachine::make_specific_snapshot(const QString& /*filename*/)
{
throw NotImplementedOnThisBackendException{"Snapshots"};
throw NotImplementedOnThisBackendException{"snapshots"};
}

} // namespace multipass
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_executable(multipass_tests
temp_file.cpp
test_alias_dict.cpp
test_argparser.cpp
test_base_snapshot.cpp
test_base_virtual_machine.cpp
test_base_virtual_machine_factory.cpp
test_basic_process.cpp
Expand All @@ -80,6 +81,7 @@ add_executable(multipass_tests
test_image_vault.cpp
test_instance_settings_handler.cpp
test_ip_address.cpp
test_json_utils.cpp
test_memory_size.cpp
test_mock_standard_paths.cpp
test_new_release_monitor.cpp
Expand All @@ -88,6 +90,7 @@ add_executable(multipass_tests
test_petname.cpp
test_platform_shared.cpp
test_private_pass_provider.cpp
test_qemu_snapshot.cpp
test_qemuimg_process_spec.cpp
test_remote_settings_handler.cpp
test_setting_specs.cpp
Expand Down
15 changes: 15 additions & 0 deletions tests/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@
// work around warning: https://github.com/google/googletest/issues/2271#issuecomment-665742471
#define MP_TYPED_TEST_SUITE(suite_name, types_param) TYPED_TEST_SUITE(suite_name, types_param, )

// Macros to make a mock delegate calls on a base class by default.
// For example, if `mock_widget` is an object of type `MockWidget` which mocks `Widget`, one can say:
// `MP_DELEGATE_MOCK_CALLS_ON_BASE(mock_widget, Widget, render);`
// This will cause calls to `mock_widget.render()` to delegate on the base implementation in `MockWidget`.
#define MP_DELEGATE_MOCK_CALLS_ON_BASE(mock, method, BaseT) \
MP_DELEGATE_MOCK_CALLS_ON_BASE_WITH_MATCHERS(mock, method, BaseT, )

// This second form accepts matchers, which are useful to disambiguate overloaded methods. For example:
// `MP_DELEGATE_MOCK_CALLS_ON_BASE_WITH_MATCHERS(mock_widget, Widget, render, (A<Canvas>()))`
// This will redirect the version of `MockWidget::render` that takes one argument of type `Canvas`.
#define MP_DELEGATE_MOCK_CALLS_ON_BASE_WITH_MATCHERS(mock, method, BaseT, ...) \
ON_CALL(mock, method __VA_ARGS__).WillByDefault([&mock](auto&&... args) { \
return mock.BaseT::method(std::forward<decltype(args)>(args)...); \
})

// Teach GTest to print Qt stuff
QT_BEGIN_NAMESPACE
class QString;
Expand Down
56 changes: 56 additions & 0 deletions tests/mock_snapshot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_MOCK_SNAPSHOT_H
#define MULTIPASS_MOCK_SNAPSHOT_H

#include "common.h"

#include <multipass/memory_size.h>
#include <multipass/snapshot.h>
#include <multipass/vm_mount.h>

namespace mp = multipass;

namespace multipass::test
{
struct MockSnapshot : public mp::Snapshot
{
MOCK_METHOD(int, get_index, (), (const, noexcept, override));
MOCK_METHOD(std::string, get_name, (), (const, override));
MOCK_METHOD(std::string, get_comment, (), (const, override));
MOCK_METHOD(QDateTime, get_creation_timestamp, (), (const, noexcept, override));
MOCK_METHOD(int, get_num_cores, (), (const, noexcept, override));
MOCK_METHOD(mp::MemorySize, get_mem_size, (), (const, noexcept, override));
MOCK_METHOD(mp::MemorySize, get_disk_space, (), (const, noexcept, override));
MOCK_METHOD(mp::VirtualMachine::State, get_state, (), (const, noexcept, override));
MOCK_METHOD((const std::unordered_map<std::string, mp::VMMount>&), get_mounts, (), (const, noexcept, override));
MOCK_METHOD(const QJsonObject&, get_metadata, (), (const, noexcept, override));
MOCK_METHOD(std::shared_ptr<const Snapshot>, get_parent, (), (const, override));
MOCK_METHOD(std::shared_ptr<Snapshot>, get_parent, (), (override));
MOCK_METHOD(std::string, get_parents_name, (), (const, override));
MOCK_METHOD(int, get_parents_index, (), (const, override));
MOCK_METHOD(void, set_name, (const std::string&), (override));
MOCK_METHOD(void, set_comment, (const std::string&), (override));
MOCK_METHOD(void, set_parent, (std::shared_ptr<Snapshot>), (override));
MOCK_METHOD(void, capture, (), (override));
MOCK_METHOD(void, erase, (), (override));
MOCK_METHOD(void, apply, (), (override));
};
} // namespace multipass::test

#endif // MULTIPASS_MOCK_SNAPSHOT_H
8 changes: 6 additions & 2 deletions tests/mock_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <multipass/mount_handler.h>
#include <multipass/virtual_machine.h>

#include <memory>

using namespace testing;

namespace multipass
Expand All @@ -41,7 +43,7 @@ struct MockVirtualMachineT : public T

template <typename... Args>
MockVirtualMachineT(std::unique_ptr<TempDir>&& tmp_dir, Args&&... args)
: T{std::forward<Args>(args)..., tmp_dir->path()}
: T{std::forward<Args>(args)..., tmp_dir->path()}, tmp_dir{std::move(tmp_dir)}
{
ON_CALL(*this, current_state()).WillByDefault(Return(multipass::VirtualMachine::State::off));
ON_CALL(*this, ssh_port()).WillByDefault(Return(42));
Expand Down Expand Up @@ -76,7 +78,7 @@ struct MockVirtualMachineT : public T
make_native_mount_handler,
(const SSHKeyProvider*, const std::string&, const VMMount&),
(override));
MOCK_METHOD(VirtualMachine::SnapshotVista, view_snapshots, (), (const, override, noexcept));
MOCK_METHOD(VirtualMachine::SnapshotVista, view_snapshots, (), (const, override));
MOCK_METHOD(int, get_num_snapshots, (), (const, override));
MOCK_METHOD(std::shared_ptr<const Snapshot>, get_snapshot, (const std::string&), (const, override));
MOCK_METHOD(std::shared_ptr<const Snapshot>, get_snapshot, (int index), (const, override));
Expand All @@ -92,6 +94,8 @@ struct MockVirtualMachineT : public T
MOCK_METHOD(void, load_snapshots, (), (override));
MOCK_METHOD(std::vector<std::string>, get_childrens_names, (const Snapshot*), (const, override));
MOCK_METHOD(int, get_snapshot_count, (), (const, override));

std::unique_ptr<TempDir> tmp_dir;
};

using MockVirtualMachine = MockVirtualMachineT<>;
Expand Down
62 changes: 62 additions & 0 deletions tests/qemu/test_qemu_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include "tests/common.h"
#include "tests/mock_environment_helpers.h"
#include "tests/mock_process_factory.h"
#include "tests/mock_snapshot.h"
#include "tests/mock_status_monitor.h"
#include "tests/mock_virtual_machine.h"
#include "tests/path.h"
#include "tests/stub_process_factory.h"
#include "tests/stub_ssh_key_provider.h"
#include "tests/stub_status_monitor.h"
Expand All @@ -35,8 +38,10 @@
#include <multipass/exceptions/start_exception.h>
#include <multipass/memory_size.h>
#include <multipass/platform.h>
#include <multipass/snapshot.h>
#include <multipass/virtual_machine.h>
#include <multipass/virtual_machine_description.h>
#include <multipass/vm_specs.h>

#include <QJsonArray>
#include <QJsonDocument>
Expand Down Expand Up @@ -675,6 +680,63 @@ TEST_F(QemuBackend, ssh_hostname_timeout_throws_and_sets_unknown_state)
EXPECT_EQ(machine.state, mp::VirtualMachine::State::unknown);
}

struct PublicSnapshotMakingQemuVM : public mpt::MockVirtualMachineT<mp::QemuVirtualMachine>
{
using mpt::MockVirtualMachineT<mp::QemuVirtualMachine>::MockVirtualMachineT;
using mp::QemuVirtualMachine::make_specific_snapshot;
using mp::QemuVirtualMachine::require_snapshots_support;
};

TEST_F(QemuBackend, supportsSnapshots)
{
PublicSnapshotMakingQemuVM vm{"asdf"};
EXPECT_NO_THROW(vm.require_snapshots_support());
}

TEST_F(QemuBackend, createsQemuSnapshotsFromSpecs)
{
PublicSnapshotMakingQemuVM machine{"mock-qemu-vm"};

auto snapshot_name = "elvis";
auto snapshot_comment = "has left the building";
const mp::VMSpecs specs{2,
mp::MemorySize{"3.21G"},
mp::MemorySize{"4.32M"},
"00:00:00:00:00:00",
{},
"asdf",
mp::VirtualMachine::State::stopped,
{},
false,
{},
{}};
auto snapshot = machine.make_specific_snapshot(snapshot_name, snapshot_comment, specs, nullptr);
EXPECT_EQ(snapshot->get_name(), snapshot_name);
EXPECT_EQ(snapshot->get_comment(), snapshot_comment);
EXPECT_EQ(snapshot->get_num_cores(), specs.num_cores);
EXPECT_EQ(snapshot->get_mem_size(), specs.mem_size);
EXPECT_EQ(snapshot->get_disk_space(), specs.disk_space);
EXPECT_EQ(snapshot->get_state(), specs.state);
EXPECT_EQ(snapshot->get_parent(), nullptr);
}

TEST_F(QemuBackend, createsQemuSnapshotsFromJsonFile)
{
PublicSnapshotMakingQemuVM machine{"mock-qemu-vm"};

const auto parent = std::make_shared<mpt::MockSnapshot>();
EXPECT_CALL(machine, get_snapshot(2)).WillOnce(Return(parent));

auto snapshot = machine.make_specific_snapshot(mpt::test_data_path_for("test_snapshot.json"));
EXPECT_EQ(snapshot->get_name(), "snapshot3");
EXPECT_EQ(snapshot->get_comment(), "A comment");
EXPECT_EQ(snapshot->get_num_cores(), 1);
EXPECT_EQ(snapshot->get_mem_size(), mp::MemorySize{"1G"});
EXPECT_EQ(snapshot->get_disk_space(), mp::MemorySize{"5G"});
EXPECT_EQ(snapshot->get_state(), mp::VirtualMachine::State::off);
EXPECT_EQ(snapshot->get_parent(), parent);
}

TEST_F(QemuBackend, lists_no_networks)
{
EXPECT_CALL(*mock_qemu_platform_factory, make_qemu_platform(_)).WillOnce([this](auto...) {
Expand Down
2 changes: 1 addition & 1 deletion tests/stub_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct StubVirtualMachine final : public multipass::VirtualMachine
{
}

StubVirtualMachine(const std::string& name, std::unique_ptr<TempDir>&& tmp_dir)
StubVirtualMachine(const std::string& name, std::unique_ptr<TempDir> tmp_dir)
: VirtualMachine{name, tmp_dir->path()}, tmp_dir{std::move(tmp_dir)}
{
}
Expand Down
4 changes: 2 additions & 2 deletions tests/stub_virtual_machine_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct StubVirtualMachineFactory : public multipass::BaseVirtualMachineFactory
{
}

StubVirtualMachineFactory(std::unique_ptr<TempDir>&& tmp_dir)
: mp::BaseVirtualMachineFactory{tmp_dir->path()}, tmp_dir{std::move(tmp_dir)}
StubVirtualMachineFactory(std::unique_ptr<TempDir> tmp_dir)
: multipass::BaseVirtualMachineFactory{tmp_dir->path()}, tmp_dir{std::move(tmp_dir)}
{
}

Expand Down
Loading