id
int64
0
755k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
65
repo_stars
int64
100
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
9 values
repo_extraction_date
stringclasses
92 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
20,982
tracking_url_downloader.h
canonical_multipass/tests/tracking_url_downloader.h
/* * 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_TRACKING_URL_DOWNLOADER_H #define MULTIPASS_TRACKING_URL_DOWNLOADER_H #include "file_operations.h" #include <multipass/url_downloader.h> namespace multipass { namespace test { struct TrackingURLDownloader : public URLDownloader { TrackingURLDownloader(const std::string& content) : URLDownloader{std::chrono::seconds(10)}, content{content} { } TrackingURLDownloader() : TrackingURLDownloader{""} { } void download_to(const QUrl& url, const QString& file_name, int64_t size, const int download_type, const ProgressMonitor&) override { make_file_with_content(file_name, content); downloaded_urls << url.toString(); downloaded_files << file_name; } QByteArray download(const QUrl& url) override { return {}; } QDateTime last_modified(const QUrl& url) override { return QDateTime::currentDateTime(); } const std::string content; QStringList downloaded_files; QStringList downloaded_urls; }; } // namespace test } // namespace multipass #endif // MULTIPASS_TRACKING_URL_DOWNLOADER_H
1,767
C++
.h
54
28.796296
113
0.724016
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,983
blueprint_test_lambdas.h
canonical_multipass/tests/blueprint_test_lambdas.h
/* * 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_BLUEPRINT_TEST_LAMBDAS_H #define MULTIPASS_BLUEPRINT_TEST_LAMBDAS_H #include <multipass/alias_definition.h> #include <multipass/fetch_type.h> #include <multipass/virtual_machine_description.h> #include <multipass/vm_image_vault.h> #include <multipass/vm_status_monitor.h> #include <optional> #include <string> namespace multipass { class Query; class VMImage; struct ClientLaunchData; class MemorySize; class SSHKeyProvider; namespace test { std::function<VMImage(const FetchType&, const Query&, const VMImageVault::PrepareAction&, const ProgressMonitor&, const bool, const std::optional<std::string>, const multipass::Path&)> fetch_image_lambda(const std::string& release, const std::string& remote, const bool must_have_checksum = false); std::function<VirtualMachine::UPtr(const VirtualMachineDescription&, const SSHKeyProvider&, VMStatusMonitor&)> create_virtual_machine_lambda(const int& num_cores, const MemorySize& mem_size, const MemorySize& disk_space, const std::string& name); std::function<Query(const std::string&, VirtualMachineDescription&, ClientLaunchData&)> fetch_blueprint_for_lambda( const int& num_cores, const MemorySize& mem_size, const MemorySize& disk_space, const std::string& release, const std::string& remote, std::optional<std::pair<std::string, AliasDefinition>> alias = std::nullopt, std::optional<std::string> workspace = std::nullopt, std::optional<std::string> sha256 = std::nullopt); } // namespace test } // namespace multipass #endif // MULTIPASS_BLUEPRINT_TEST_LAMBDAS_H
2,401
C++
.h
54
38.648148
115
0.708904
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,984
stub_vm_image_vault.h
canonical_multipass/tests/stub_vm_image_vault.h
/* * 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_STUB_VM_IMAGE_VAULT_H #define MULTIPASS_STUB_VM_IMAGE_VAULT_H #include "temp_file.h" #include <multipass/vm_image_vault.h> namespace multipass { namespace test { struct StubVMImageVault final : public multipass::VMImageVault { multipass::VMImage fetch_image(const multipass::FetchType&, const multipass::Query&, const PrepareAction& prepare, const multipass::ProgressMonitor&, const bool, const std::optional<std::string>&, const multipass::Path&) override { return prepare({dummy_image.name(), {}, {}, {}, {}, {}}); }; void remove(const std::string&) override{}; bool has_record_for(const std::string&) override { return false; } void prune_expired_images() override{}; void update_images(const FetchType& fetch_type, const PrepareAction& prepare, const ProgressMonitor& monitor) override{}; MemorySize minimum_image_size_for(const std::string& image) override { return MemorySize{}; } VMImageHost* image_host_for(const std::string& remote_name) const override { return nullptr; } std::vector<std::pair<std::string, VMImageInfo>> all_info_for(const Query& query) const override { return {}; } void clone(const std::string& source_instance_name, const std::string& destination_instance_name) override { } TempFile dummy_image; }; } } #endif // MULTIPASS_STUB_VM_IMAGE_VAULT_H
2,294
C++
.h
64
28.796875
110
0.646237
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,985
mock_terminal.h
canonical_multipass/tests/mock_terminal.h
/* * 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_TERMINAL_H #define MULTIPASS_MOCK_TERMINAL_H #include "common.h" #include <multipass/terminal.h> namespace multipass { namespace test { struct MockTerminal : public Terminal { MOCK_METHOD(std::istream&, cin, (), (override)); MOCK_METHOD(std::ostream&, cout, (), (override)); MOCK_METHOD(std::ostream&, cerr, (), (override)); MOCK_METHOD(bool, cin_is_live, (), (const, override)); MOCK_METHOD(bool, cout_is_live, (), (const, override)); MOCK_METHOD(void, set_cin_echo, (const bool), (override)); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_TERMINAL_H
1,258
C++
.h
36
32.75
72
0.727422
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,986
file_operations.h
canonical_multipass/tests/file_operations.h
/* * 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/>. * * Authored by: Chris Townsend <christopher.townsend@canonical.com> * Alberto Aguirre <alberto.aguirre@canonical.com> * */ #ifndef MULTIPASS_FILE_READER_H #define MULTIPASS_FILE_READER_H #include <QByteArray> #include <QString> namespace multipass { namespace test { QByteArray load(QString path); QByteArray load_test_file(const char* file_name); void make_file_with_content(const QString& file_name, const std::string& content = "this is a test file"); } } #endif // MULTIPASS_FILE_READER_H
1,136
C++
.h
33
32.787879
106
0.760909
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,987
stub_process_factory.h
canonical_multipass/tests/stub_process_factory.h
/* * 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_STUB_PROCESS_FACTORY_H #define MULTIPASS_STUB_PROCESS_FACTORY_H #include "common.h" #include "process_factory.h" // rely on build system to include the right implementation #include <multipass/process/process.h> namespace multipass { namespace test { class StubProcessFactory : public ProcessFactory { public: struct ProcessInfo { QString command; QStringList arguments; }; // StubProcessFactory installed with Inject() call, and uninstalled when the Scope object deleted struct Scope { ~Scope(); // Get info about the Processes launched with this list std::vector<ProcessInfo> process_list(); }; static std::unique_ptr<Scope> Inject(); // Implementation using ProcessFactory::ProcessFactory; std::unique_ptr<Process> create_process(std::unique_ptr<ProcessSpec>&& spec) const override; private: static StubProcessFactory& stub_instance(); std::vector<ProcessInfo> process_list; }; } // namespace test } // namespace multipass #endif // MULTIPASS_STUB_PROCESS_FACTORY_H
1,720
C++
.h
51
30.372549
101
0.743961
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,988
mock_json_utils.h
canonical_multipass/tests/mock_json_utils.h
/* * 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_JSON_UTILS_H #define MULTIPASS_MOCK_JSON_UTILS_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/json_utils.h> namespace multipass::test { class MockJsonUtils : public JsonUtils { public: using JsonUtils::JsonUtils; MOCK_METHOD(void, write_json, (const QJsonObject&, QString), (const, override)); MOCK_METHOD(std::string, json_to_string, (const QJsonObject& root), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockJsonUtils, JsonUtils); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_JSON_UTILS_H
1,216
C++
.h
33
34.69697
91
0.758503
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,989
mock_utils.h
canonical_multipass/tests/mock_utils.h
/* * 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_UTILS_H #define MULTIPASS_MOCK_UTILS_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/ssh/ssh_key_provider.h> #include <multipass/utils.h> #include <multipass/virtual_machine.h> namespace multipass::test { class MockUtils : public Utils { public: using Utils::Utils; MOCK_METHOD(qint64, filesystem_bytes_available, (const QString&), (const, override)); MOCK_METHOD(void, exit, (int), (override)); MOCK_METHOD(std::string, run_cmd_for_output, (const QString&, const QStringList&, const int), (const, override)); MOCK_METHOD(bool, run_cmd_for_status, (const QString&, const QStringList&, const int), (const, override)); MOCK_METHOD(std::string, contents_of, (const multipass::Path&), (const, override)); MOCK_METHOD(void, make_file_with_content, (const std::string&, const std::string&), ()); MOCK_METHOD(void, make_file_with_content, (const std::string&, const std::string&, const bool&), (override)); MOCK_METHOD(Path, make_dir, (const QDir&, const QString&, QFileDevice::Permissions), (override)); MOCK_METHOD(Path, make_dir, (const QDir&, QFileDevice::Permissions), (override)); MOCK_METHOD(std::string, get_kernel_version, (), (const, override)); MOCK_METHOD(QString, generate_scrypt_hash_for, (const QString&), (const, override)); MOCK_METHOD(bool, client_certs_exist, (const QString&), (const)); MOCK_METHOD(void, copy_client_certs_to_common_dir, (const QString&, const QString&), (const)); MOCK_METHOD(bool, is_running, (const VirtualMachine::State& state), (const, override)); MOCK_METHOD(std::string, run_in_ssh_session, (SSHSession & session, const std::string& cmd, bool whisper), (const, override)); MOCK_METHOD(QString, make_uuid, (const std::optional<std::string>&), (const, override)); MOCK_METHOD(void, sleep_for, (const std::chrono::milliseconds&), (const, override)); MOCK_METHOD(bool, is_ipv4_valid, (const std::string& ipv4), (const, override)); MOCK_METHOD(Path, default_mount_target, (const Path& source), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockUtils, Utils); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_UTILS_H
2,880
C++
.h
55
48.6
117
0.710638
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,990
stub_ssh_key_provider.h
canonical_multipass/tests/stub_ssh_key_provider.h
/* * 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/>. * * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com> * */ #ifndef MULTIPASS_STUB_SSH_KEY_PROVIDER_H #define MULTIPASS_STUB_SSH_KEY_PROVIDER_H #include <multipass/ssh/ssh_key_provider.h> namespace multipass { namespace test { class StubSSHKeyProvider : public SSHKeyProvider { public: std::string private_key_as_base64() const override { return {}; } std::string public_key_as_base64() const override { return {}; } ssh_key private_key() const override { return nullptr; } }; } } #endif // MULTIPASS_STUB_SSH_KEY_PROVIDER_H
1,225
C++
.h
44
24.977273
72
0.730442
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,991
mock_logger.h
canonical_multipass/tests/mock_logger.h
/* * 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_LOGGER_H #define MULTIPASS_MOCK_LOGGER_H #include "common.h" #include <multipass/logging/log.h> #include <multipass/logging/logger.h> #include <multipass/private_pass_provider.h> namespace multipass { namespace test { class MockLogger : public multipass::logging::Logger, public PrivatePassProvider<MockLogger> { public: MockLogger(const PrivatePass&, const multipass::logging::Level logging_level); MOCK_METHOD(void, log, (multipass::logging::Level level, multipass::logging::CString category, multipass::logging::CString message), (const, override)); class Scope { public: ~Scope(); std::shared_ptr<testing::NiceMock<MockLogger>> mock_logger; private: Scope(const multipass::logging::Level logging_level); friend class MockLogger; }; // only one at a time, please [[nodiscard]] static Scope inject(const multipass::logging::Level logging_level = multipass::logging::Level::error); template <typename Matcher> static auto make_cstring_matcher(const Matcher& matcher); void expect_log(multipass::logging::Level lvl, const std::string& substr, const testing::Cardinality& times = testing::Exactly(1)); // Reject logs with severity `lvl` or higher (lower integer), accept the rest // By default, all logs are rejected. Pass error level to accept everything but errors (expect those explicitly) void screen_logs(multipass::logging::Level lvl = multipass::logging::Level::trace); }; } // namespace test } // namespace multipass template <typename Matcher> auto multipass::test::MockLogger::make_cstring_matcher(const Matcher& matcher) { return testing::Property(&multipass::logging::CString::c_str, matcher); } #endif // MULTIPASS_MOCK_LOGGER_H
2,470
C++
.h
61
36.327869
120
0.72788
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,992
disabling_macros.h
canonical_multipass/tests/disabling_macros.h
/* * 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_DISABLING_MACROS_H #define MULTIPASS_DISABLING_MACROS_H // Macros to disable tests - prepend to test or test suite names // Use like this: TEST_F(TestSuite, DISABLE_ON_XXX(test_name)) // See https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#temporarily-disabling-tests #ifdef MULTIPASS_PLATFORM_WINDOWS #define DISABLE_ON_WINDOWS(test_name) DISABLED_##test_name #define DISABLE_ON_WINDOWS_AND_MACOS(test_name) DISABLED_##test_name #define DISABLE_ON_MACOS(test_name) test_name #elif MULTIPASS_PLATFORM_APPLE #define DISABLE_ON_WINDOWS(test_name) test_name #define DISABLE_ON_WINDOWS_AND_MACOS(test_name) DISABLED_##test_name #define DISABLE_ON_MACOS(test_name) DISABLED_##test_name #else // Linux #define DISABLE_ON_WINDOWS(test_name) test_name #define DISABLE_ON_WINDOWS_AND_MACOS(test_name) test_name #define DISABLE_ON_MACOS(test_name) test_name #endif #endif // MULTIPASS_DISABLING_MACROS_H
1,578
C++
.h
35
43.371429
111
0.782779
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,993
mock_network.h
canonical_multipass/tests/mock_network.h
/* * 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_NETWORK_H #define MULTIPASS_MOCK_NETWORK_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/url_downloader.h> #include <QNetworkAccessManager> #include <QNetworkReply> namespace multipass::test { class MockQNetworkAccessManager : public QNetworkAccessManager { public: MOCK_METHOD(QNetworkReply*, createRequest, (Operation, const QNetworkRequest&, QIODevice*), (override)); }; class MockQNetworkReply : public QNetworkReply { public: MockQNetworkReply() { open(QIODevice::ReadOnly); }; MOCK_METHOD(qint64, readData, (char*, qint64), (override)); void abort_operation() { setError(OperationCanceledError, "Operation canceled"); emit errorOccurred(OperationCanceledError); setFinished(true); emit finished(); }; void set_error(QNetworkReply::NetworkError errorCode, const QString& errorString) { setError(errorCode, errorString); }; void set_attribute(QNetworkRequest::Attribute code, const QVariant& value) { setAttribute(code, value); }; void set_header(QNetworkRequest::KnownHeaders header, const QVariant& value) { setHeader(header, value); } public Q_SLOTS: MOCK_METHOD(void, abort, (), (override)); }; class MockNetworkManagerFactory : public NetworkManagerFactory { public: using NetworkManagerFactory::NetworkManagerFactory; MOCK_METHOD(std::unique_ptr<QNetworkAccessManager>, make_network_manager, (const Path&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockNetworkManagerFactory, NetworkManagerFactory); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_NETWORK_H
2,332
C++
.h
69
30.202899
112
0.745883
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,994
fake_key_data.h
canonical_multipass/tests/fake_key_data.h
/* * 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_FAKE_KEY_DATA_H #define MULTIPASS_FAKE_KEY_DATA_H namespace multipass { namespace test { constexpr auto fake_key_data = "-----BEGIN RSA PRIVATE KEY-----\n" "MIIEpAIBAAKCAQEAv3lEFtxT3kd2OrWQ8k3v1SHILNDwwm9U7awNbLDqVEresZNd\n" "mRGmH381fO8tHpNdeQ+XEMff16FZiMKRQWx5OlHTQ33cS7X/huZ5Ge5YVKsBMmqy\n" "vJADK7Ud38mNaKi3hqepD87labVmY1ARTNHSLDG68c5bIyquvzbawwwkM7qPTbw5\n" "ZHOEpKehwPZ/034oPnmPV3BAbX1HySi/zrOZE/D1JW3uHvhF1yprDWhJumOVBSYB\n" "zDloJSsFfFEEYOzkdmAwZ0q3yfMVxLiwTlP2Hhf+i8kOzjQfz29PPfNwroYJZqKT\n" "Eg8YAqBr28ryHzHa8W+htUoZbntID2w9aDeJ2wIDAQABAoIBABpk0vf7wyve2fNZ\n" "1/MuvyK4F2nmG2oSArkIgIk9EfAwqeX8lGhnQGkTFgJ0zdlrIvVvKrnLc5W7ziXF\n" "/FPyafuaD+87yEQ/gEvONV9XtaFmOTID90N67pT10HpqxC1rJHFRZ0KgmIsr0ENc\n" "ZCYcvkYNTOHMOk/ssE33d8xvPgZLMf/EvVqcgPyhJXXg0Y1po9cLPQjCBCfmigiM\n" "U+3Hlrz8w6rtp3RUuM2jzrA+uHQGSa4fC/Wn2WT5fR2RZz7BPdJ+kHlTfFRq27oy\n" "lsTITYDJf26ej1wmsWIV4AqznV33xSRZBK6KZjq98D6MKc28fyfZQKxnc1jWG1Xi\n" "erLM+YECgYEA73wVxCdX/9eBXlquQ5wrj94UFOV9zlbr/oE0CYZC8SkG6fCf9/a/\n" "lUUz25CK+kugJcOFHOmOXIjydXzDDFXEUgsf6MeX0WiLy6rvFdlq3xnQ9oUKBzCv\n" "6gLL9s2Ozo4NMeY3rlqxAswdyGx3f5HHkB722MeUlafjXPkJ82m61GECgYEAzK2V\n" "iX1v+b76HG9XnDd1eK0L/JINSJrFJUMD1KhY84FmXqPoBWcuoEtUPA+cvOhAzr3l\n" "TFqKbXbY5JVx1c66uEkCMYYVPYyOVZNnEz+bGOmrK2NaYDwIySG6WhD2Zh69VIXa\n" "kfvMzba0M26FXjWBDN3oluT6RLBHb2xdZgMHx7sCgYB1B3QziO5t7cggbbve+kAn\n" "a+TwWT1jSgLFOipNxTiNVPk19QqXSBNTRKAU2cuwiKhYC/XOrSuOeLXTSAagzoDD\n" "fwA25uJ/yNEX1A5F5RteruT4swa1gMtWVcuKbeUtdylnixMGtvbtYQXk3WyAAKM/\n" "AIKsaMtpXsOyuVhthOtxwQKBgQCBvIGtzcHdd01IGtdYoNqoLGANr3IWFGxkSw8x\n" "i6geaWY/FPvr+NRYLIdvLqI2J610nm+qrzVRX2Tpt0SZttkqGLT4OTpbci2CVtWe\n" "INIpv2uNLAPMPiF/hA6AKoJUhqWR3uqFYCsYNfgRJbwJ1DZBtqNIikmMooQVP4YQ\n" "NFmJIwKBgQCjxMF4SFzzRbNfiHKLL39D8RHlCPalbmX2CXaiUT4H1rq2oK3EiI+O\n" "+SzzmxbHAjFRRuKeqhmC9+yhhHssBt6lJe71Fl3e01McjOcW9P1AZQdgYsDyCqR0\n" "Yy460TKDO1em0N9GlXfsYgiSFJv1WmD7M/kvGpGxSERcnR4+bBd2BQ==\n" "-----END RSA PRIVATE KEY-----\n"; } // namespace test } // namespace multipass #endif // MULTIPASS_FAKE_KEY_DATA_H
3,444
C++
.h
52
49.384615
99
0.660077
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,995
stub_vm_blueprint_provider.h
canonical_multipass/tests/stub_vm_blueprint_provider.h
/* * 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_STUB_WORKFLOW_PROVIDER #define MULTIPASS_STUB_WORKFLOW_PROVIDER #include <multipass/exceptions/blueprint_exceptions.h> #include <multipass/vm_blueprint_provider.h> namespace multipass { namespace test { struct StubVMBlueprintProvider final : public VMBlueprintProvider { Query fetch_blueprint_for(const std::string& blueprint_name, VirtualMachineDescription& vm_desc, ClientLaunchData& client_launch_data) override { throw std::out_of_range(""); } Query blueprint_from_file(const std::string& path, const std::string& blueprint_name, VirtualMachineDescription& vm_desc, ClientLaunchData& client_launch_data) override { throw InvalidBlueprintException(""); } std::optional<VMImageInfo> info_for(const std::string& blueprint_name) override { return VMImageInfo(); } std::vector<VMImageInfo> all_blueprints() override { return {}; } std::string name_from_blueprint(const std::string& blueprint_name) override { return {}; } int blueprint_timeout(const std::string& blueprint_name) override { return 0; } }; } // namespace test } // namespace multipass #endif // MULTIPASS_STUB_WORKFLOW_PROVIDER
1,925
C++
.h
56
29.767857
112
0.714286
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,996
stub_console.h
canonical_multipass/tests/stub_console.h
/* * 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_STUB_CONSOLE_H #define MULTIPASS_STUB_CONSOLE_H #include <multipass/console.h> namespace multipass { namespace test { struct StubConsole final : public multipass::Console { void read_console() override{}; void write_console() override{}; void exit_console() override{}; }; } } #endif // MULTIPASS_STUB_CONSOLE_H
975
C++
.h
32
28.46875
72
0.75693
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,997
daemon_test_fixture.h
canonical_multipass/tests/daemon_test_fixture.h
/* * 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_DAEMON_TEST_FIXTURE_H #define MULTIPASS_DAEMON_TEST_FIXTURE_H // This include must go first because it comes from premock. #include "mock_ssh_test_fixture.h" #include "mock_virtual_machine_factory.h" #include "temp_dir.h" #include <src/daemon/daemon.h> #include <src/daemon/daemon_config.h> #include <multipass/rpc/multipass.grpc.pb.h> #include <QEventLoop> #include <QThread> #include <memory> #include <optional> #include <unordered_map> using namespace testing; namespace mp = multipass; namespace multipass { namespace test { struct DaemonTestFixture : public ::Test { DaemonTestFixture(); void SetUp() override; MockVirtualMachineFactory* use_a_mock_vm_factory(); void send_command(const std::vector<std::string>& command, std::ostream& cout = trash_stream, std::ostream& cerr = trash_stream, std::istream& cin = trash_stream); void send_commands(std::vector<std::vector<std::string>> commands, std::ostream& cout = trash_stream, std::ostream& cerr = trash_stream, std::istream& cin = trash_stream); int total_lines_of_output(std::stringstream& output); std::string fake_json_contents(const std::string& default_mac, const std::vector<mp::NetworkInterface>& extra_ifaces, const std::unordered_map<std::string, mp::VMMount>& mounts = {}); std::pair<std::unique_ptr<TempDir>, QString> // unique_ptr bypasses missing move ctor plant_instance_json(const std::string& contents); template <typename R> bool is_ready(std::future<R> const& f); /** * Helper function to call one of the <em>daemon slots</em> that ultimately handle RPC requests * (e.g. @c mp::Daemon::get). It takes care of promise/future boilerplate. This will generally be given a * @c mpt::MockServerReaderWriter, which can be used to verify replies. * @tparam DaemonSlotPtr The method pointer type for the provided slot. Example: * @code * void (mp::Daemon::*)(const mp::GetRequest *, grpc::ServerReaderWriterInterface<mp::GetReply> *, * std::promise<grpc::Status> *)> * @endcode * @tparam Request The request type that the provided slot expects. Example: @c mp::GetRequest * @tparam Server The concrete @c grpc::ServerWriterInterface type that the provided slot expects. The template * needs to be instantiated with the correct reply type. Example: <tt> grpc::ServerWriterInterface\<mp\::GetReply\> * </tt> * @param daemon The daemon object to call the slot on. * @param slot A pointer to the daemon slot method that should be called. * @param request The request to call the slot with. * @param server The concrete @c grpc::ServerWriterInterface to call the slot with (see doc on Server typename). * This will generally be a @c mpt::MockServerWriter. Notice that this is a <em>universal reference</em>, so it will * bind to both lvalue and rvalue references. * @return The @c grpc::Status that is produced by the slot */ template <typename DaemonSlotPtr, typename Request, typename Server> grpc::Status call_daemon_slot(Daemon& daemon, DaemonSlotPtr slot, const Request& request, Server&& server); MockSSHTestFixture mock_ssh_test_fixture; #ifdef MULTIPASS_PLATFORM_WINDOWS std::string server_address{"localhost:50051"}; #else std::string server_address{"unix:/tmp/test-multipassd.socket"}; #endif QEventLoop loop; // needed as signal/slots used internally by mp::Daemon TempDir cache_dir; TempDir data_dir; DaemonConfigBuilder config_builder; inline static std::stringstream trash_stream{}; // this may have contents (that we don't care about) }; } // namespace test } // namespace multipass #endif // MULTIPASS_DAEMON_TEST_FIXTURE_H
4,498
C++
.h
91
44.725275
120
0.713993
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,998
mock_image_host.h
canonical_multipass/tests/mock_image_host.h
/* * 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_IMAGE_HOST_H #define MULTIPASS_MOCK_IMAGE_HOST_H #include "common.h" #include "temp_file.h" #include <multipass/query.h> #include <multipass/vm_image_host.h> using namespace testing; namespace multipass { namespace test { constexpr auto default_id = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; constexpr auto default_release_info = "18.04 LTS"; constexpr auto default_version = "20200519.1"; constexpr auto default_stream_location = "https://some/stream"; constexpr auto default_alias = "default"; constexpr auto snapcraft_image_id = "c14a2047c6ba57722bc612115b1d44bea4a29ac2212fcc0628c49aa832dba867"; constexpr auto lxd_snapcraft_image_id = "da708063589b9c83dfeaec7049deac82da96f8969b413d1346dc067897e5934b"; constexpr auto snapcraft_release_info = "Snapcraft builder for Core 20"; constexpr auto snapcraft_image_version = "20200901"; constexpr auto snapcraft_alias = "snapcraft"; constexpr auto custom_image_id = "aedb5a84aaf2e4e443e090511156366a2800c26cec1b6a46f44d153c4bf04205"; constexpr auto lxd_custom_image_id = "bc5a973bd6f2bef30658fb51177cf5e506c1d60958a4c97813ee26416dc368da"; constexpr auto custom_release_info = "Custom Ubuntu for Testing"; constexpr auto custom_image_version = "20200909"; constexpr auto custom_alias = "custom"; constexpr auto another_image_id = "e34a2047c6ba57722bc612115b1d44bea4a29ac2212fcc0628c49aa832dba867"; constexpr auto another_image_version = "20200501"; constexpr auto another_release_info = "Another Ubuntu Version"; constexpr auto another_alias = "another"; constexpr auto release_remote = "release"; constexpr auto snapcraft_remote = "snapcraft"; constexpr auto custom_remote = "custom"; class MockImageHost : public VMImageHost { public: MockImageHost() { ON_CALL(*this, info_for(_)).WillByDefault([this](const auto& query) { if (query.release == snapcraft_remote) { return mock_snapcraft_image_info; } else if (query.release == custom_remote) { return mock_custom_image_info; } else { return mock_bionic_image_info; } }); ON_CALL(*this, all_info_for(_)).WillByDefault(Return(empty_image_info_vector_pair)); ON_CALL(*this, info_for_full_hash(_)).WillByDefault(Return(empty_vm_image_info)); ON_CALL(*this, all_images_for(_, _)).WillByDefault(Return(empty_image_info_vector)); ON_CALL(*this, for_each_entry_do(_)).WillByDefault([this](const Action& action) { action(release_remote, mock_bionic_image_info); action(release_remote, mock_another_image_info); action(snapcraft_remote, mock_snapcraft_image_info); action(custom_remote, mock_custom_image_info); }); ON_CALL(*this, supported_remotes()).WillByDefault(Return(remote)); }; MOCK_METHOD(std::optional<VMImageInfo>, info_for, (const Query&), (override)); MOCK_METHOD((std::vector<std::pair<std::string, VMImageInfo>>), all_info_for, (const Query&), (override)); MOCK_METHOD(VMImageInfo, info_for_full_hash, (const std::string&), (override)); MOCK_METHOD(std::vector<VMImageInfo>, all_images_for, (const std::string&, const bool), (override)); MOCK_METHOD(void, for_each_entry_do, (const Action&), (override)); MOCK_METHOD(std::vector<std::string>, supported_remotes, (), (override)); MOCK_METHOD(void, update_manifests, (bool), (override)); TempFile image; VMImageInfo mock_bionic_image_info{{default_alias}, "Ubuntu", "bionic", default_release_info, "Bionic Beaver", true, image.url(), default_id, default_stream_location, default_version, 1, true}; VMImageInfo mock_snapcraft_image_info{{snapcraft_alias}, "Ubuntu", "core20", snapcraft_release_info, "Core 20", true, image.url(), snapcraft_image_id, "", snapcraft_image_version, 1, true}; VMImageInfo mock_custom_image_info{{custom_alias}, "Ubuntu", "Custom Core", custom_release_info, "Custom Core", true, image.url(), custom_image_id, "", custom_image_version, 1, false}; VMImageInfo mock_another_image_info{{another_alias}, "Ubuntu", "another", another_release_info, "Another", true, image.url(), another_image_id, "", another_image_version, 1, false}; private: std::vector<std::pair<std::string, VMImageInfo>> empty_image_info_vector_pair; std::vector<VMImageInfo> empty_image_info_vector; VMImageInfo empty_vm_image_info{{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, -1, {}}; std::vector<std::string> remote{{"release"}}; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_IMAGE_HOST_H
7,051
C++
.h
144
33.152778
110
0.539388
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
20,999
mock_client_platform.h
canonical_multipass/tests/mock_client_platform.h
/* * 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_CLIENT_PLATFORM_H #define MULTIPASS_MOCK_CLIENT_PLATFORM_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/cli/client_platform.h> namespace multipass { class Terminal; namespace test { class MockClientPlatform : public cli::platform::Platform { public: using Platform::Platform; MOCK_METHOD((std::string), get_password, (Terminal*), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockClientPlatform, Platform); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_CLIENT_PLATFORM_H
1,201
C++
.h
35
32.342857
77
0.76943
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,000
mock_client_rpc.h
canonical_multipass/tests/mock_client_rpc.h
/* * 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_CLIENT_RPC_H #define MULTIPASS_MOCK_CLIENT_RPC_H #include "common.h" #include <multipass/rpc/multipass.grpc.pb.h> using namespace testing; namespace multipass::test { template <class W, class R> class MockClientReaderWriter : public grpc::ClientReaderWriterInterface<W, R> { public: MockClientReaderWriter() { EXPECT_CALL(*this, Read(_)).WillRepeatedly(Return(false)); EXPECT_CALL(*this, Finish()).WillRepeatedly(Return(grpc::Status())); } MOCK_METHOD(grpc::Status, Finish, (), (override)); MOCK_METHOD(bool, NextMessageSize, (uint32_t * sz), (override)); MOCK_METHOD(bool, Read, (R * msg), (override)); MOCK_METHOD(void, WaitForInitialMetadata, (), (override)); MOCK_METHOD(bool, Write, (const W& msg, grpc::WriteOptions options), (override)); MOCK_METHOD(bool, WritesDone, (), (override)); }; class MockRpcStub : public multipass::Rpc::StubInterface { public: MockRpcStub() = default; MOCK_METHOD(grpc::Status, ping, (grpc::ClientContext * context, const multipass::PingRequest& request, multipass::PingReply* response), (override)); // originally private // NB: we're sort of relying on gRPC implementation here... but it's only for tests and we can update as needed MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), createRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), AsynccreateRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), PrepareAsynccreateRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), launchRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), AsynclaunchRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::LaunchRequest, multipass::LaunchReply>*), PrepareAsynclaunchRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::PurgeRequest, multipass::PurgeReply>*), purgeRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::PurgeRequest, multipass::PurgeReply>*), AsyncpurgeRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::PurgeRequest, multipass::PurgeReply>*), PrepareAsyncpurgeRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::FindRequest, multipass::FindReply>*), findRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::FindRequest, multipass::FindReply>*), AsyncfindRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::FindRequest, multipass::FindReply>*), PrepareAsyncfindRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::InfoRequest, multipass::InfoReply>*), infoRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::InfoRequest, multipass::InfoReply>*), AsyncinfoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::InfoRequest, multipass::InfoReply>*), PrepareAsyncinfoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::ListRequest, multipass::ListReply>*), listRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::ListRequest, multipass::ListReply>*), AsynclistRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::ListRequest, multipass::ListReply>*), PrepareAsynclistRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::NetworksRequest, multipass::NetworksReply>*), networksRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::NetworksRequest, multipass::NetworksReply>*), AsyncnetworksRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::NetworksRequest, multipass::NetworksReply>*), PrepareAsyncnetworksRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::MountRequest, multipass::MountReply>*), mountRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::MountRequest, multipass::MountReply>*), AsyncmountRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::MountRequest, multipass::MountReply>*), PrepareAsyncmountRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD(grpc::ClientAsyncResponseReaderInterface<multipass::PingReply>*, AsyncpingRaw, (grpc::ClientContext * context, const multipass::PingRequest& request, grpc::CompletionQueue* cq), (override)); MOCK_METHOD(grpc::ClientAsyncResponseReaderInterface<multipass::PingReply>*, PrepareAsyncpingRaw, (grpc::ClientContext * context, const multipass::PingRequest& request, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::RecoverRequest, multipass::RecoverReply>*), recoverRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RecoverRequest, multipass::RecoverReply>*), AsyncrecoverRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RecoverRequest, multipass::RecoverReply>*), PrepareAsyncrecoverRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::SSHInfoRequest, multipass::SSHInfoReply>*), ssh_infoRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SSHInfoRequest, multipass::SSHInfoReply>*), Asyncssh_infoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SSHInfoRequest, multipass::SSHInfoReply>*), PrepareAsyncssh_infoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::StartRequest, multipass::StartReply>*), startRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::StartRequest, multipass::StartReply>*), AsyncstartRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::StartRequest, multipass::StartReply>*), PrepareAsyncstartRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::StopRequest, multipass::StopReply>*), stopRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::StopRequest, multipass::StopReply>*), AsyncstopRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::StopRequest, multipass::StopReply>*), PrepareAsyncstopRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::SuspendRequest, multipass::SuspendReply>*), suspendRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SuspendRequest, multipass::SuspendReply>*), AsyncsuspendRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SuspendRequest, multipass::SuspendReply>*), PrepareAsyncsuspendRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::RestartRequest, multipass::RestartReply>*), restartRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RestartRequest, multipass::RestartReply>*), AsyncrestartRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RestartRequest, multipass::RestartReply>*), PrepareAsyncrestartRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::DeleteRequest, multipass::DeleteReply>*), deletRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::DeleteRequest, multipass::DeleteReply>*), AsyncdeletRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::DeleteRequest, multipass::DeleteReply>*), PrepareAsyncdeletRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::UmountRequest, multipass::UmountReply>*), umountRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::UmountRequest, multipass::UmountReply>*), AsyncumountRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::UmountRequest, multipass::UmountReply>*), PrepareAsyncumountRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::VersionRequest, multipass::VersionReply>*), versionRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::VersionRequest, multipass::VersionReply>*), AsyncversionRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::VersionRequest, multipass::VersionReply>*), PrepareAsyncversionRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::GetRequest, multipass::GetReply>*), getRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::GetRequest, multipass::GetReply>*), AsyncgetRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::GetRequest, multipass::GetReply>*), PrepareAsyncgetRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::SetRequest, multipass::SetReply>*), setRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SetRequest, multipass::SetReply>*), AsyncsetRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SetRequest, multipass::SetReply>*), PrepareAsyncsetRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::KeysRequest, multipass::KeysReply>*), keysRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::KeysRequest, multipass::KeysReply>*), AsynckeysRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::KeysRequest, multipass::KeysReply>*), PrepareAsynckeysRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::AuthenticateRequest, multipass::AuthenticateReply>*), authenticateRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::AuthenticateRequest, multipass::AuthenticateReply>*), AsyncauthenticateRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::AuthenticateRequest, multipass::AuthenticateReply>*), PrepareAsyncauthenticateRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::SnapshotRequest, multipass::SnapshotReply>*), snapshotRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SnapshotRequest, multipass::SnapshotReply>*), AsyncsnapshotRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::SnapshotRequest, multipass::SnapshotReply>*), PrepareAsyncsnapshotRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::RestoreRequest, multipass::RestoreReply>*), restoreRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RestoreRequest, multipass::RestoreReply>*), AsyncrestoreRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::RestoreRequest, multipass::RestoreReply>*), PrepareAsyncrestoreRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::CloneRequest, multipass::CloneReply>*), cloneRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::CloneRequest, multipass::CloneReply>*), AsynccloneRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::CloneRequest, multipass::CloneReply>*), PrepareAsynccloneRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); MOCK_METHOD((grpc::ClientReaderWriterInterface<multipass::DaemonInfoRequest, multipass::DaemonInfoReply>*), daemon_infoRaw, (grpc::ClientContext * context), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::DaemonInfoRequest, multipass::DaemonInfoReply>*), Asyncdaemon_infoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq, void* tag), (override)); MOCK_METHOD((grpc::ClientAsyncReaderWriterInterface<multipass::DaemonInfoRequest, multipass::DaemonInfoReply>*), PrepareAsyncdaemon_infoRaw, (grpc::ClientContext * context, grpc::CompletionQueue* cq), (override)); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_CLIENT_RPC_H
18,466
C++
.h
232
69.556034
120
0.709394
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,001
mock_poco_zip_utils.h
canonical_multipass/tests/mock_poco_zip_utils.h
/* * 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_POCO_ZIP_UTILS_H #define MULTIPASS_MOCK_POCO_ZIP_UTILS_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/poco_zip_utils.h> namespace multipass::test { class MockPocoZipUtils : public PocoZipUtils { public: using PocoZipUtils::PocoZipUtils; MOCK_METHOD(Poco::Zip::ZipArchive, zip_archive_for, (std::ifstream&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockPocoZipUtils, PocoZipUtils); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_POCO_ZIP_UTILS_H
1,167
C++
.h
32
34.40625
93
0.765071
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,002
mock_format_utils.h
canonical_multipass/tests/mock_format_utils.h
/* * 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_FORMAT_UTILS_H #define MULTIPASS_MOCK_FORMAT_UTILS_H #include "mock_singleton_helpers.h" #include <multipass/cli/format_utils.h> namespace multipass::test { class MockFormatUtils : public FormatUtils { public: using FormatUtils::FormatUtils; MOCK_METHOD(std::string, convert_to_user_locale, (const google::protobuf::Timestamp&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockFormatUtils, FormatUtils); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_FORMAT_UTILS_H
1,154
C++
.h
31
35.129032
110
0.767921
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,003
mock_backend_utils.h
canonical_multipass/tests/mock_backend_utils.h
/* * 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_BACKEND_UTILS_H #define MULTIPASS_MOCK_BACKEND_UTILS_H #include "common.h" #include "mock_singleton_helpers.h" #include <src/platform/backends/shared/linux/backend_utils.h> namespace multipass::test { class MockBackend : public Backend { public: using Backend::Backend; MOCK_METHOD(std::string, create_bridge_with, (const std::string&), (override)); MOCK_METHOD(std::string, get_subnet, (const Path&, const QString&), (const, override)); MOCK_METHOD(void, check_for_kvm_support, (), (override)); MOCK_METHOD(void, check_if_kvm_is_in_use, (), (override)); MP_MOCK_SINGLETON_BOILERPLATE(MockBackend, Backend); }; class MockLinuxSysCalls : public LinuxSysCalls { public: using LinuxSysCalls::LinuxSysCalls; MOCK_METHOD(int, close, (int), (const, override)); MOCK_METHOD(int, ioctl, (int, unsigned long, unsigned long), (const, override)); MOCK_METHOD(int, open, (const char*, mode_t), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockLinuxSysCalls, LinuxSysCalls); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_BACKEND_UTILS_H
1,747
C++
.h
44
37.136364
91
0.74306
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,004
path.h
canonical_multipass/tests/path.h
/* * 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/>. * * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com> * */ #ifndef MULTIPASS_TEST_DATA_PATH_H #define MULTIPASS_TEST_DATA_PATH_H #include <QString> namespace multipass { namespace test { QString test_data_path(); QString test_data_path_for(const char* file_name); QString test_data_sub_dir_path(const char* dir_name); std::string mock_bin_path(); } // namespace test } // namespace multipass #endif // MULTIPASS_TEST_DATA_PATH_H
1,068
C++
.h
32
31.75
72
0.763795
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,005
stub_virtual_machine_factory.h
canonical_multipass/tests/stub_virtual_machine_factory.h
/* * 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_STUB_VIRTUAL_MACHINE_FACTORY_H #define MULTIPASS_STUB_VIRTUAL_MACHINE_FACTORY_H #include "stub_virtual_machine.h" #include "stub_vm_image_vault.h" #include "temp_dir.h" #include <platform/backends/shared/base_virtual_machine_factory.h> namespace multipass { namespace test { struct StubVirtualMachineFactory : public multipass::BaseVirtualMachineFactory { StubVirtualMachineFactory() : StubVirtualMachineFactory{std::make_unique<TempDir>()} { } StubVirtualMachineFactory(std::unique_ptr<TempDir> tmp_dir) : multipass::BaseVirtualMachineFactory{tmp_dir->path()}, tmp_dir{std::move(tmp_dir)} { } VirtualMachine::UPtr create_virtual_machine(const VirtualMachineDescription&, const SSHKeyProvider&, VMStatusMonitor&) override { return std::make_unique<StubVirtualMachine>(); } multipass::VirtualMachine::UPtr create_vm_and_clone_instance_dir_data(const VMSpecs& src_vm_spec, const VMSpecs& dest_vm_spec, const std::string& source_name, const std::string& destination_name, const VMImage& dest_vm_image, const SSHKeyProvider& key_provider, VMStatusMonitor& monitor) override { return std::make_unique<StubVirtualMachine>(); } void remove_resources_for_impl(const std::string& name) override { } multipass::FetchType fetch_type() override { return multipass::FetchType::ImageOnly; } multipass::VMImage prepare_source_image(const multipass::VMImage& source_image) override { return source_image; } void prepare_instance_image(const multipass::VMImage& instance_image, const multipass::VirtualMachineDescription& vm_desc) override { } void hypervisor_health_check() override { } QString get_backend_directory_name() const override { return {}; } QString get_instance_directory(const std::string& name) const override { return tmp_dir->path(); } QString get_backend_version_string() const override { return "stub-5678"; } multipass::VMImageVault::UPtr create_image_vault(std::vector<VMImageHost*> image_hosts, URLDownloader* downloader, const Path& cache_dir_path, const Path& data_dir_path, const days& days_to_expire) override { return std::make_unique<StubVMImageVault>(); } void require_suspend_support() const override { throw NotImplementedOnThisBackendException{"suspend"}; } std::unique_ptr<TempDir> tmp_dir; }; } } #endif // MULTIPASS_STUB_VIRTUAL_MACHINE_FACTORY_H
3,861
C++
.h
96
29.177083
118
0.601708
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,006
mock_qsettings.h
canonical_multipass/tests/mock_qsettings.h
/* * 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_QSETTINGS_H #define MULTIPASS_MOCK_QSETTINGS_H #include "common.h" #include "mock_singleton_helpers.h" #include <src/settings/wrapped_qsettings.h> namespace multipass::test { class MockQSettings : public WrappedQSettings { public: using WrappedQSettings::WrappedQSettings; // promote visibility MOCK_METHOD(QSettings::Status, status, (), (const, override)); MOCK_METHOD(QString, fileName, (), (const, override)); MOCK_METHOD(QVariant, value_impl, (const QString& key, const QVariant& default_value), (const, override)); // promote visibility MOCK_METHOD(void, sync, (), (override)); MOCK_METHOD(void, setValue, (const QString& key, const QVariant& value), (override)); MOCK_METHOD(void, remove, (const QString&), (override)); }; class MockQSettingsProvider : public WrappedQSettingsFactory { public: using WrappedQSettingsFactory::WrappedQSettingsFactory; MOCK_METHOD(std::unique_ptr<WrappedQSettings>, make_wrapped_qsettings, (const QString&, QSettings::Format), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockQSettingsProvider, WrappedQSettingsFactory); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_QSETTINGS_H
1,863
C++
.h
45
38.333333
111
0.748344
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,007
mock_vm_image_vault.h
canonical_multipass/tests/mock_vm_image_vault.h
/* * 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_IMAGE_VAULT_H #define MULTIPASS_MOCK_IMAGE_VAULT_H #include "common.h" #include "temp_file.h" #include <multipass/query.h> #include <multipass/vm_image_vault.h> using namespace testing; namespace multipass { namespace test { class MockVMImageVault : public VMImageVault { public: MockVMImageVault() { ON_CALL(*this, fetch_image(_, _, _, _, _, _, _)) .WillByDefault([this](auto, auto, const PrepareAction& prepare, auto, auto, auto, auto) { return VMImage{dummy_image.name(), {}, {}, {}, {}, {}}; }); ON_CALL(*this, has_record_for(_)).WillByDefault(Return(true)); ON_CALL(*this, minimum_image_size_for(_)).WillByDefault(Return(MemorySize{"1048576"})); }; MOCK_METHOD(VMImage, fetch_image, (const FetchType&, const Query&, const PrepareAction&, const ProgressMonitor&, const bool, const std::optional<std::string>&, const mp::Path&), (override)); MOCK_METHOD(void, remove, (const std::string&), (override)); MOCK_METHOD(bool, has_record_for, (const std::string&), (override)); MOCK_METHOD(void, prune_expired_images, (), (override)); MOCK_METHOD(void, update_images, (const FetchType&, const PrepareAction&, const ProgressMonitor&), (override)); MOCK_METHOD(MemorySize, minimum_image_size_for, (const std::string&), (override)); MOCK_METHOD(void, clone, (const std::string&, const std::string&), (override)); MOCK_METHOD(VMImageHost*, image_host_for, (const std::string&), (const, override)); MOCK_METHOD((std::vector<std::pair<std::string, VMImageInfo>>), all_info_for, (const Query&), (const, override)); private: TempFile dummy_image; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_IMAGE_VAULT_H
2,548
C++
.h
63
34.857143
117
0.660476
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,008
temp_file.h
canonical_multipass/tests/temp_file.h
/* * 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/>. * * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com> * */ #ifndef MULTIPASS_TEMP_FILE_H #define MULTIPASS_TEMP_FILE_H #include <QString> #include <QTemporaryFile> #include <QUrl> namespace multipass { namespace test { class TempFile { public: TempFile(); QString name() const { return the_name; } QString url() const { return the_url; } private: QTemporaryFile file; QString the_name; QString the_url; }; } } #endif // MULTIPASS_TEMP_FILE_H
1,106
C++
.h
41
24.878049
72
0.748351
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,009
dummy_ssh_key_provider.h
canonical_multipass/tests/dummy_ssh_key_provider.h
/* * 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/>. * * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com> * */ #ifndef MULTIPASS_DUMMY_SSH_KEY_PROVIDER_H #define MULTIPASS_DUMMY_SSH_KEY_PROVIDER_H #include "stub_ssh_key_provider.h" namespace multipass { namespace test { class DummyKeyProvider : public StubSSHKeyProvider { public: explicit DummyKeyProvider(std::string key) : key{std::move(key)} { } std::string public_key_as_base64() const override { return key; }; private: std::string key; }; } // namespace test } // namespace multipass #endif // MULTIPASS_DUMMY_SSH_KEY_PROVIDER_H
1,211
C++
.h
41
27.146341
72
0.746141
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,010
mock_virtual_machine_factory.h
canonical_multipass/tests/mock_virtual_machine_factory.h
/* * 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_VIRTUAL_MACHINE_FACTORY_H #define MULTIPASS_MOCK_VIRTUAL_MACHINE_FACTORY_H #include "common.h" #include <multipass/network_interface_info.h> #include <multipass/virtual_machine_description.h> #include <multipass/virtual_machine_factory.h> #include <multipass/vm_status_monitor.h> namespace multipass { namespace test { struct MockVirtualMachineFactory : public VirtualMachineFactory { MOCK_METHOD(VirtualMachine::UPtr, create_virtual_machine, (const VirtualMachineDescription&, const SSHKeyProvider&, VMStatusMonitor&), (override)); MOCK_METHOD(VirtualMachine::UPtr, create_vm_and_clone_instance_dir_data, (const VMSpecs&, const VMSpecs&, const std::string&, const std::string&, const VMImage&, const SSHKeyProvider&, VMStatusMonitor&), (override)); MOCK_METHOD(void, remove_resources_for, (const std::string&), (override)); MOCK_METHOD(FetchType, fetch_type, (), (override)); MOCK_METHOD(void, prepare_networking, (std::vector<NetworkInterface>&), (override)); MOCK_METHOD(VMImage, prepare_source_image, (const VMImage&), (override)); MOCK_METHOD(void, prepare_instance_image, (const VMImage&, const VirtualMachineDescription&), (override)); MOCK_METHOD(void, hypervisor_health_check, (), (override)); MOCK_METHOD(QString, get_backend_directory_name, (), (const, override)); MOCK_METHOD(QString, get_instance_directory, (const std::string&), (const, override)); MOCK_METHOD(QString, get_backend_version_string, (), (const, override)); MOCK_METHOD(VMImageVault::UPtr, create_image_vault, (std::vector<VMImageHost*>, URLDownloader*, const Path&, const Path&, const days&), (override)); MOCK_METHOD(void, configure, (VirtualMachineDescription&), (override)); MOCK_METHOD(std::vector<NetworkInterfaceInfo>, networks, (), (const, override)); MOCK_METHOD(void, require_snapshots_support, (), (const, override)); MOCK_METHOD(void, require_suspend_support, (), (const, override)); MOCK_METHOD(void, require_clone_support, (), (const, override)); // originally protected: MOCK_METHOD(std::string, create_bridge_with, (const NetworkInterfaceInfo&), (override)); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_VIRTUAL_MACHINE_FACTORY_H
3,099
C++
.h
65
41.892308
112
0.698151
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,011
mock_ssh_process_exit_status.h
canonical_multipass/tests/mock_ssh_process_exit_status.h
/* * 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_SSH_PROCESS_EXIT_STATUS #define MULTIPASS_MOCK_SSH_PROCESS_EXIT_STATUS #include "mock_ssh.h" #include <optional> namespace multipass::test { class ExitStatusMock { public: ExitStatusMock() { add_channel_cbs = [this](ssh_channel, ssh_channel_callbacks cb) { channel_cbs = cb; return SSH_OK; }; event_do_poll = [this](auto...) { if (channel_cbs == nullptr) return SSH_ERROR; if (exit_code) channel_cbs->channel_exit_status_function(nullptr, nullptr, *exit_code, channel_cbs->userdata); return ssh_rc; }; } ~ExitStatusMock() { add_channel_cbs = std::move(old_add_channel_cbs); event_do_poll = std::move(old_event_do_poll); } void set_ssh_rc(int rc) { ssh_rc = rc; } void set_no_exit() { exit_code.reset(); } void set_exit_status(int code) { exit_code = code; } static constexpr int success_status = 0; static constexpr int failure_status = 42; private: decltype(mock_ssh_add_channel_callbacks)& add_channel_cbs{mock_ssh_add_channel_callbacks}; decltype(mock_ssh_add_channel_callbacks) old_add_channel_cbs{std::move(mock_ssh_add_channel_callbacks)}; decltype(mock_ssh_event_dopoll)& event_do_poll{mock_ssh_event_dopoll}; decltype(mock_ssh_event_dopoll) old_event_do_poll{std::move(mock_ssh_event_dopoll)}; int ssh_rc{SSH_OK}; std::optional<int> exit_code{0}; ssh_channel_callbacks channel_cbs{nullptr}; }; } // namespace multipass::test #endif // MULTIPASS_MOCK_SSH_PROCESS_EXIT_STATUS
2,307
C++
.h
69
28.246377
111
0.673112
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,012
json_test_utils.h
canonical_multipass/tests/json_test_utils.h
/* * 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_JSON_TEST_UTILS_H #define MULTIPASS_JSON_TEST_UTILS_H #include "temp_dir.h" #include <multipass/network_interface.h> #include <multipass/vm_mount.h> #include <string> #include <unordered_map> #include <vector> #include <QString> namespace mp = multipass; namespace mpt = multipass::test; std::string make_instance_json(const std::optional<std::string>& default_mac = std::nullopt, const std::vector<mp::NetworkInterface>& extra_ifaces = {}, const std::vector<std::string>& extra_instances = {}); std::unique_ptr<mpt::TempDir> plant_instance_json(const std::string& contents); // unique_ptr bypasses missing move ctor void check_interfaces_in_json(const QString& file, const std::string& mac, const std::vector<mp::NetworkInterface>& extra_interfaces); void check_mounts_in_json(const QString& file, std::unordered_map<std::string, mp::VMMount>& mounts); #endif // MULTIPASS_JSON_TEST_UTILS_H
1,641
C++
.h
35
42.514286
120
0.719122
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,013
stub_virtual_machine.h
canonical_multipass/tests/stub_virtual_machine.h
/* * 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_STUB_VIRTUAL_MACHINE_H #define MULTIPASS_STUB_VIRTUAL_MACHINE_H #include "stub_mount_handler.h" #include "stub_snapshot.h" #include "temp_dir.h" #include <multipass/virtual_machine.h> namespace multipass { namespace test { struct StubVirtualMachine final : public multipass::VirtualMachine { StubVirtualMachine() : StubVirtualMachine{"stub"} { } StubVirtualMachine(const std::string& name) : StubVirtualMachine{name, std::make_unique<TempDir>()} { } StubVirtualMachine(const std::string& name, std::unique_ptr<TempDir> tmp_dir) : VirtualMachine{name, tmp_dir->path()}, tmp_dir{std::move(tmp_dir)} { } void start() override { } void shutdown(ShutdownPolicy shutdown_policy = ShutdownPolicy::Powerdown) override { } void suspend() override { } multipass::VirtualMachine::State current_state() override { return multipass::VirtualMachine::State::off; } int ssh_port() override { return 42; } std::string ssh_hostname(std::chrono::milliseconds) override { return "localhost"; } std::string ssh_username() override { return "ubuntu"; } std::string management_ipv4() override { return {}; } std::vector<std::string> get_all_ipv4() override { return std::vector<std::string>{"192.168.2.123"}; } std::string ipv6() override { return {}; } std::string ssh_exec(const std::string& cmd, bool whisper = false) override { return {}; } void ensure_vm_is_running() override { throw std::runtime_error("Not running"); } void wait_until_ssh_up(std::chrono::milliseconds) override { } void wait_for_cloud_init(std::chrono::milliseconds timeout) override { } void update_state() override { } void update_cpus(int num_cores) override { } void resize_memory(const MemorySize&) override { } void resize_disk(const MemorySize&) override { } void add_network_interface(int, const std::string&, const NetworkInterface&) override { } std::unique_ptr<MountHandler> make_native_mount_handler(const std::string&, const VMMount&) override { return std::make_unique<StubMountHandler>(); } SnapshotVista view_snapshots() const override { return {}; } int get_num_snapshots() const override { return 0; } std::shared_ptr<const Snapshot> get_snapshot(const std::string&) const override { return {}; } std::shared_ptr<Snapshot> get_snapshot(const std::string&) override { return {}; } std::shared_ptr<const Snapshot> get_snapshot(int) const override { return nullptr; } std::shared_ptr<Snapshot> get_snapshot(int) override { return nullptr; } std::shared_ptr<const Snapshot> take_snapshot(const VMSpecs&, const std::string&, const std::string&) override { return {}; } void rename_snapshot(const std::string& old_name, const std::string& new_name) override { } void delete_snapshot(const std::string&) override { } void restore_snapshot(const std::string& name, VMSpecs& specs) override { } void load_snapshots() override { } std::vector<std::string> get_childrens_names(const Snapshot*) const override { return {}; } int get_snapshot_count() const override { return 0; } void remove_snapshots_from_image() const override { } StubSnapshot snapshot; std::unique_ptr<TempDir> tmp_dir; }; } // namespace test } // namespace multipass #endif // MULTIPASS_STUB_VIRTUAL_MACHINE_H
4,438
C++
.h
165
21.848485
114
0.661389
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,014
mock_daemon.h
canonical_multipass/tests/mock_daemon.h
/* * 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_DAEMON_H #define MULTIPASS_MOCK_DAEMON_H #include "common.h" #include <src/daemon/daemon.h> #include <src/daemon/daemon_rpc.h> namespace multipass { namespace test { struct MockDaemon : public Daemon { using Daemon::Daemon; MOCK_METHOD(void, shutdown_grpc_server, (), (override)); MOCK_METHOD(void, create, (const CreateRequest*, (grpc::ServerReaderWriterInterface<CreateReply, CreateRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, launch, (const LaunchRequest*, (grpc::ServerReaderWriterInterface<LaunchReply, LaunchRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, purge, (const PurgeRequest*, (grpc::ServerReaderWriterInterface<PurgeReply, PurgeRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, find, (const FindRequest* request, (grpc::ServerReaderWriterInterface<FindReply, FindRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, info, (const InfoRequest*, (grpc::ServerReaderWriterInterface<InfoReply, InfoRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, list, (const ListRequest*, (grpc::ServerReaderWriterInterface<ListReply, ListRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, mount, (const MountRequest* request, (grpc::ServerReaderWriterInterface<MountReply, MountRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, recover, (const RecoverRequest*, (grpc::ServerReaderWriterInterface<RecoverReply, RecoverRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, ssh_info, (const SSHInfoRequest*, (grpc::ServerReaderWriterInterface<SSHInfoReply, SSHInfoRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, start, (const StartRequest*, (grpc::ServerReaderWriterInterface<StartReply, StartRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, stop, (const StopRequest*, (grpc::ServerReaderWriterInterface<StopReply, StopRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, suspend, (const SuspendRequest*, (grpc::ServerReaderWriterInterface<SuspendReply, SuspendRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, restart, (const RestartRequest*, (grpc::ServerReaderWriterInterface<RestartReply, RestartRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, delet, (const DeleteRequest*, (grpc::ServerReaderWriterInterface<DeleteReply, DeleteRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, umount, (const UmountRequest*, (grpc::ServerReaderWriterInterface<UmountReply, UmountRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, version, (const VersionRequest*, (grpc::ServerReaderWriterInterface<VersionReply, VersionRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, keys, (const KeysRequest*, (grpc::ServerReaderWriterInterface<KeysReply, KeysRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, get, (const GetRequest*, (grpc::ServerReaderWriterInterface<GetReply, GetRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, set, (const SetRequest*, (grpc::ServerReaderWriterInterface<SetReply, SetRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, networks, (const NetworksRequest*, (grpc::ServerReaderWriterInterface<NetworksReply, NetworksRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, authenticate, (const AuthenticateRequest*, (grpc::ServerReaderWriterInterface<AuthenticateReply, AuthenticateRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, snapshot, (const SnapshotRequest*, (grpc::ServerReaderWriterInterface<SnapshotReply, SnapshotRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, restore, (const RestoreRequest*, (grpc::ServerReaderWriterInterface<RestoreReply, RestoreRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, clone, (const CloneRequest*, (grpc::ServerReaderWriterInterface<CloneReply, CloneRequest>*), std::promise<grpc::Status>*), (override)); MOCK_METHOD(void, daemon_info, (const DaemonInfoRequest*, (grpc::ServerReaderWriterInterface<DaemonInfoReply, DaemonInfoRequest>*), std::promise<grpc::Status>*), (override)); template <typename Request, typename Reply> void set_promise_value(const Request*, grpc::ServerReaderWriterInterface<Reply, Request>*, std::promise<grpc::Status>* status_promise) { status_promise->set_value(grpc::Status::OK); } // The following functions are meant to test daemon's bridging functions. // This tests bridged interface addition. void test_add_bridged_interface(const std::string& instance_name, const VirtualMachine::ShPtr instance, const VMSpecs& specs = {}) { vm_instance_specs.emplace(instance_name, specs); operative_instances.insert(std::make_pair(instance_name, instance)); return add_bridged_interface(instance_name); } // This tests if the daemon is able to tell whether an instance has a bridged interface or not. bool test_is_bridged(const std::string& instance_name, const VMSpecs& specs) { vm_instance_specs.insert(std::make_pair(instance_name, specs)); return is_bridged(instance_name); } }; } // namespace test } // namespace multipass #endif // MULTIPASS_TESTS_MOCK_DAEMON_H
7,597
C++
.h
164
34.908537
110
0.606657
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,015
mock_mount_handler.h
canonical_multipass/tests/mock_mount_handler.h
/* * 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_MOUNT_HANDLER_H #define MULTIPASS_MOCK_MOUNT_HANDLER_H #include <multipass/mount_handler.h> namespace multipass::test { class MockMountHandler : public MountHandler { public: MOCK_METHOD(void, activate_impl, (ServerVariant, std::chrono::milliseconds), (override)); MOCK_METHOD(void, deactivate_impl, (bool), (override)); MOCK_METHOD(bool, is_active, (), (override)); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_MOUNT_HANDLER_H
1,108
C++
.h
30
34.933333
93
0.755349
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,016
stub_status_monitor.h
canonical_multipass/tests/stub_status_monitor.h
/* * 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_STUB_STATUS_MONITOR_H #define MULTIPASS_STUB_STATUS_MONITOR_H #include <multipass/vm_status_monitor.h> namespace multipass { namespace test { struct StubVMStatusMonitor : public multipass::VMStatusMonitor { void on_resume() override{}; ; void on_shutdown() override{}; void on_suspend() override{}; void on_restart(const std::string& name) override{}; void persist_state_for(const std::string& name, const VirtualMachine::State& state) override{}; void update_metadata_for(const std::string& name, const QJsonObject& metadata) override{}; QJsonObject retrieve_metadata_for(const std::string& name) override { return QJsonObject(); }; }; } } #endif // MULTIPASS_STUB_STATUS_MONITOR_H
1,380
C++
.h
40
31.85
99
0.745699
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,017
mock_stdcin.h
canonical_multipass/tests/mock_stdcin.h
/* * 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_STDCIN_H #define MULTIPASS_MOCK_STDCIN_H #include <iostream> #include <sstream> class MockStdCin { public: MockStdCin(const std::string& s) { fake_cin << s; // Backup and replace std::cin's streambuffer cin_backup = std::cin.rdbuf(); std::streambuf* psbuf = fake_cin.rdbuf(); std::cin.rdbuf(psbuf); // assign streambuf to cin } ~MockStdCin() { // Restore cin's original streanbuffer std::cin.rdbuf(cin_backup); } private: std::streambuf* cin_backup; std::stringstream fake_cin; }; #endif // MULTIPASS_MOCK_STDCIN_H
1,261
C++
.h
41
27.073171
72
0.702391
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,018
mock_standard_paths.h
canonical_multipass/tests/mock_standard_paths.h
/* * 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_STANDARD_PATHS_H #define MULTIPASS_MOCK_STANDARD_PATHS_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/standard_paths.h> namespace multipass::test { // This will automatically verify expectations set upon it at the end of each test class MockStandardPaths : public StandardPaths { public: using StandardPaths::StandardPaths; static void mockit(); static MockStandardPaths& mock_instance(); MOCK_METHOD(QString, locate, (StandardLocation, const QString&, LocateOptions), (const, override)); MOCK_METHOD(QStringList, standardLocations, (StandardLocation type), (const, override)); MOCK_METHOD(QString, writableLocation, (StandardLocation type), (const, override)); private: void setup_mock_defaults(); friend class MockSingletonHelper<MockStandardPaths, ::testing::NiceMock>; }; } // namespace multipass::test #endif // MULTIPASS_MOCK_STANDARD_PATHS_H
1,572
C++
.h
39
37.871795
103
0.770341
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,019
mock_server_reader_writer.h
canonical_multipass/tests/mock_server_reader_writer.h
/* * 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_SERVER_WRITER_H #define MULTIPASS_MOCK_SERVER_WRITER_H #include <multipass/rpc/multipass.grpc.pb.h> namespace multipass { namespace test { template <typename W, typename R> class MockServerReaderWriter : public grpc::ServerReaderWriterInterface<W, R> { public: MOCK_METHOD(void, SendInitialMetadata, (), (override)); MOCK_METHOD(bool, Write, (const W& msg, grpc::WriteOptions options), (override)); MOCK_METHOD(bool, NextMessageSize, (uint32_t*), (override)); MOCK_METHOD(bool, Read, (R*), (override)); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_SERVER_WRITER_H
1,263
C++
.h
35
34.085714
85
0.753268
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,020
mock_url_downloader.h
canonical_multipass/tests/mock_url_downloader.h
/* * 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_URL_DOWNLOADER_H #define MULTIPASS_MOCK_URL_DOWNLOADER_H #include <multipass/url_downloader.h> namespace multipass { namespace test { struct MockURLDownloader : public multipass::URLDownloader { MockURLDownloader() : URLDownloader{std::chrono::seconds(10)} {}; MOCK_METHOD(QByteArray, download, (const QUrl&), (override)); MOCK_METHOD(QByteArray, download, (const QUrl&, bool), (override)); MOCK_METHOD(QDateTime, last_modified, (const QUrl&), (override)); MOCK_METHOD(void, download_to, (const QUrl&, const QString&, int64_t, const int, const ProgressMonitor&), (override)); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_URL_DOWNLOADER_H
1,357
C++
.h
35
36.2
109
0.742792
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,021
mock_sftp_utils.h
canonical_multipass/tests/mock_sftp_utils.h
#ifndef MOCK_SFTP_UTILS_H #define MOCK_SFTP_UTILS_H #include "mock_singleton_helpers.h" #include <multipass/ssh/sftp_utils.h> namespace multipass::test { struct MockSFTPUtils : public SFTPUtils { using SFTPUtils::SFTPUtils; MOCK_METHOD(fs::path, get_local_file_target, (const fs::path& source_path, const fs::path& target_path, bool make_parent), (override)); MOCK_METHOD(fs::path, get_remote_file_target, (sftp_session sftp, const fs::path& source_path, const fs::path& target_path, bool make_parent), (override)); MOCK_METHOD(fs::path, get_local_dir_target, (const fs::path& source_path, const fs::path& target_path, bool make_parent), (override)); MOCK_METHOD(fs::path, get_remote_dir_target, (sftp_session sftp, const fs::path& source_path, const fs::path& target_path, bool make_parent), (override)); MOCK_METHOD(void, mkdir_recursive, (sftp_session sftp, const fs::path& path), (override)); MOCK_METHOD(std::unique_ptr<SFTPDirIterator>, make_SFTPDirIterator, (sftp_session sftp, const fs::path& path), (override)); MOCK_METHOD(std::unique_ptr<SFTPClient>, make_SFTPClient, (const std::string& host, int port, const std::string& username, const std::string& priv_key_blob), (override)); MP_MOCK_SINGLETON_BOILERPLATE(MockSFTPUtils, SFTPUtils); }; } // namespace multipass::test #endif // MOCK_SFTP_UTILS_H
1,497
C++
.h
29
44.206897
115
0.665527
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,022
stub_cert_store.h
canonical_multipass/tests/stub_cert_store.h
/* * 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_TESTS_STUB_CERT_STORE_H #define MULTIPASS_TESTS_STUB_CERT_STORE_H #include <multipass/cert_store.h> namespace multipass { namespace test { class StubCertStore : public CertStore { public: void add_cert(const std::string& pem_cert) override { } std::string PEM_cert_chain() const override { return {}; } bool verify_cert(const std::string& pem_cert) override { return true; } bool empty() override { return true; } }; } // namespace test } // namespace multipass #endif // MULTIPASS_TESTS_STUB_CERT_STORE_H
1,230
C++
.h
45
24.266667
72
0.720102
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,023
mock_process_factory.h
canonical_multipass/tests/mock_process_factory.h
/* * 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_PROCESS_FACTORY_H #define MULTIPASS_MOCK_PROCESS_FACTORY_H #include "common.h" #include "process_factory.h" // rely on build system to include the right implementation #include <multipass/process/process.h> #include <functional> using namespace testing; namespace multipass { namespace test { class MockProcess; class MockProcessFactory : public ProcessFactory { public: struct ProcessInfo { QString command; QStringList arguments; }; using Callback = std::function<void(MockProcess*)>; // MockProcessFactory installed with Inject() call, and uninstalled when the Scope object deleted struct Scope { ~Scope(); // Get info about the Processes launched with this list std::vector<ProcessInfo> process_list(); // To mock the created Process, register a callback to be called on each Process creation // Only one callback is supported void register_callback(const Callback& callback); }; static std::unique_ptr<Scope> Inject(); // Implementation using ProcessFactory::ProcessFactory; std::unique_ptr<Process> create_process(std::unique_ptr<ProcessSpec>&& spec) const override; private: static MockProcessFactory& mock_instance(); void register_callback(const Callback& callback); std::vector<ProcessInfo> process_list; std::optional<Callback> callback; }; class MockProcess : public Process { public: MOCK_METHOD(void, start, (), (override)); MOCK_METHOD(void, terminate, (), (override)); MOCK_METHOD(void, kill, (), (override)); MOCK_METHOD(bool, running, (), (const, override)); MOCK_METHOD(ProcessState, process_state, (), (const, override)); MOCK_METHOD(QString, error_string, (), (const, override)); MOCK_METHOD(qint64, process_id, (), (const, override)); MOCK_METHOD(ProcessState, execute, (int), (override)); MOCK_METHOD(qint64, write, (const QByteArray&), (override)); MOCK_METHOD(bool, wait_for_started, (int msecs), (override)); MOCK_METHOD(bool, wait_for_finished, (int msecs), (override)); MockProcess(std::unique_ptr<ProcessSpec>&& spec, std::vector<MockProcessFactory::ProcessInfo>& process_list); QString program() const override; QStringList arguments() const override; QString working_directory() const override; QProcessEnvironment process_environment() const override; bool wait_for_ready_read(int msecs = 30000) override; MOCK_METHOD(QByteArray, read_all_standard_output, (), (override)); MOCK_METHOD(QByteArray, read_all_standard_error, (), (override)); void close_write_channel() override; void set_process_channel_mode(QProcess::ProcessChannelMode) override; void setup_child_process() override; private: const std::unique_ptr<ProcessSpec> spec; ProcessState success_exit_state; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_PROCESS_FACTORY_H
3,584
C++
.h
89
36.359551
113
0.73036
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,024
mock_recursive_dir_iterator.h
canonical_multipass/tests/mock_recursive_dir_iterator.h
/* * 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_STD_RECURSIVE_DIR_ITER_H #define MULTIPASS_MOCK_STD_RECURSIVE_DIR_ITER_H #include "common.h" #include <multipass/recursive_dir_iterator.h> namespace multipass::test { struct MockDirectoryEntry : public DirectoryEntry { MOCK_METHOD(void, assign, (const fs::path& path), (override)); MOCK_METHOD(void, assign, (const fs::path& path, std::error_code& err), (override)); MOCK_METHOD(void, replace_filename, (const fs::path& path), (override)); MOCK_METHOD(void, replace_filename, (const fs::path& path, std::error_code& err), (override)); MOCK_METHOD(void, refresh, (), (override)); MOCK_METHOD(void, refresh, (std::error_code & err), (noexcept, override)); MOCK_METHOD(const fs::path&, path, (), (const, noexcept, override)); MOCK_METHOD(bool, exists, (), (const, override)); MOCK_METHOD(bool, exists, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_block_file, (), (const, override)); MOCK_METHOD(bool, is_block_file, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_character_file, (), (const, override)); MOCK_METHOD(bool, is_character_file, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_directory, (), (const, override)); MOCK_METHOD(bool, is_directory, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_fifo, (), (const, override)); MOCK_METHOD(bool, is_fifo, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_other, (), (const, override)); MOCK_METHOD(bool, is_other, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_regular_file, (), (const, override)); MOCK_METHOD(bool, is_regular_file, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_socket, (), (const, override)); MOCK_METHOD(bool, is_socket, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(bool, is_symlink, (), (const, override)); MOCK_METHOD(bool, is_symlink, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(uintmax_t, file_size, (), (const, override)); MOCK_METHOD(uintmax_t, file_size, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(uintmax_t, hard_link_count, (), (const, override)); MOCK_METHOD(uintmax_t, hard_link_count, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(fs::file_time_type, last_write_time, (), (const, override)); MOCK_METHOD(fs::file_time_type, last_write_time, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(fs::file_status, status, (), (const, override)); MOCK_METHOD(fs::file_status, status, (std::error_code & err), (const, noexcept, override)); MOCK_METHOD(fs::file_status, symlink_status, (), (const, override)); MOCK_METHOD(fs::file_status, symlink_status, (std::error_code & err), (const, noexcept, override)); }; struct MockRecursiveDirIterator : public RecursiveDirIterator { MOCK_METHOD(bool, hasNext, (), (override)); MOCK_METHOD(const DirectoryEntry&, next, (), (override)); }; struct MockDirIterator : public DirIterator { MOCK_METHOD(bool, hasNext, (), (override)); MOCK_METHOD(const DirectoryEntry&, next, (), (override)); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_STD_RECURSIVE_DIR_ITER_H
4,010
C++
.h
72
52.236111
107
0.692014
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,025
mischievous_url_downloader.h
canonical_multipass/tests/mischievous_url_downloader.h
/* * 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_MISCHIEVOUS_URL_DOWNLOADER_H #define MULTIPASS_MISCHIEVOUS_URL_DOWNLOADER_H #include <multipass/url_downloader.h> #include <QUrl> namespace multipass { namespace test { class MischievousURLDownloader : public URLDownloader { public: MischievousURLDownloader(std::chrono::milliseconds timeout); void download_to(const QUrl& url, const QString& file_name, int64_t size, const int download_type, const ProgressMonitor& monitor) override; QByteArray download(const QUrl& url) override; QByteArray download(const QUrl& url, const bool is_force_update_from_network) override; QDateTime last_modified(const QUrl& url) override; public: int mischiefs = 0; private: const QUrl& choose_url(const QUrl& url); QUrl empty_url = {}; }; } // namespace test } // namespace multipass #endif /* MULTIPASS_MISCHIEVOUS_URL_DOWNLOADER_H */
1,527
C++
.h
42
33.52381
102
0.757453
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,026
fake_handle.h
canonical_multipass/tests/fake_handle.h
/* * 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/>. * */ namespace multipass { namespace test { template <typename T> auto fake_handle() { return reinterpret_cast<T>(0xDEADBEEF); } } // namespace test } // namespace multipass
802
C++
.h
27
27.962963
72
0.757106
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,027
signal.h
canonical_multipass/tests/signal.h
/* * 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_SIGNAL_H #define MULTIPASS_SIGNAL_H #include <condition_variable> #include <mutex> namespace multipass { namespace test { struct Signal { template <typename T> bool wait_for(const T& timeout) { std::unique_lock<std::mutex> lock{mutex}; return cv.wait_for(lock, timeout, [this] { return signaled; }); } void wait() { std::unique_lock<decltype(mutex)> lock{mutex}; cv.wait(lock, [this] { return signaled; }); } void signal() { std::lock_guard<decltype(mutex)> lg{mutex}; signaled = true; cv.notify_one(); } std::mutex mutex; std::condition_variable cv; bool signaled{false}; }; } // namespace test } // namespace multipass #endif // MULTIPASS_SIGNAL_TEST_FIXTURE_H
1,423
C++
.h
50
24.88
72
0.694952
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,028
mock_settings.h
canonical_multipass/tests/mock_settings.h
/* * 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_SETTINGS_H #define MULTIPASS_MOCK_SETTINGS_H #include "common.h" #include "mock_singleton_helpers.h" #include <multipass/settings/settings.h> namespace multipass::test { class MockSettings : public Settings { public: using Settings::Settings; MOCK_METHOD(SettingsHandler*, register_handler, (std::unique_ptr<SettingsHandler>), (override)); MOCK_METHOD(void, unregister_handler, (SettingsHandler * handler), (override)); MOCK_METHOD(QString, get, (const QString&), (const, override)); MOCK_METHOD(void, set, (const QString&, const QString&), (override)); MOCK_METHOD(std::set<QString>, keys, (), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockSettings, Settings); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_SETTINGS_H
1,426
C++
.h
36
37.222222
100
0.749819
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,029
common.h
canonical_multipass/tests/common.h
/* * 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_COMMON_H #define MULTIPASS_COMMON_H #include <multipass/format.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <algorithm> // Extra macros for testing exceptions. // // * MP_{ASSERT|EXPECT}_THROW_THAT(statement, expected_exception, matcher): // Tests that the statement throws an exception of the expected type, matching the provided matcher #define MP_EXPECT_THROW_THAT(statement, expected_exception, matcher) \ EXPECT_THROW( \ { \ try \ { \ statement; \ } \ catch (const expected_exception& e) \ { \ EXPECT_THAT(e, matcher); \ throw; \ } \ }, \ expected_exception) #define MP_ASSERT_THROW_THAT(statement, expected_exception, matcher) \ ASSERT_THROW( \ { \ try \ { \ statement; \ } \ catch (const expected_exception& e) \ { \ ASSERT_THAT(e, matcher); \ throw; \ } \ }, \ expected_exception) // 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([m = &mock](auto&&... args) { \ return m->BaseT::method(std::forward<decltype(args)>(args)...); \ }) // Teach GTest to print Qt stuff QT_BEGIN_NAMESPACE class QString; void PrintTo(const QString& qstr, std::ostream* os); QT_END_NAMESPACE // Teach GTest to print multipass stuff namespace multipass { struct NetworkInterface; struct NetworkInterfaceInfo; void PrintTo(const NetworkInterface& net, std::ostream* os); void PrintTo(const NetworkInterfaceInfo& net, std::ostream* os); } // namespace multipass // Matchers namespace multipass::test { /** * Adapt an n-ary callable to a unary callable receiving an n-tuple. * @details This is useful to create matchers with Truly (which expects a unary predicate). * @tparam F The type of the callable. * @param f The n-ary callable we want to adapt. Note that this argument may be copied. * @return A unary callable that receives an n-tuple, calls \c f with that tuple unpacked, and returns what @c f returns */ template <typename F> auto with_arg_tuple(F f) { return [f](auto&& arg_tuple) // may copy f, but avoiding forwarding-capture mess (see https://v.gd/2IbEdv) { return std::apply(f, std::forward<decltype(arg_tuple)>(arg_tuple)); }; } template <typename MsgMatcher> auto match_what(MsgMatcher&& matcher) { return testing::Property(&std::exception::what, std::forward<MsgMatcher>(matcher)); } template <typename StrMatcher> auto match_qstring(StrMatcher&& matcher) { return testing::Property(&QString::toStdString, std::forward<StrMatcher>(matcher)); } } // namespace multipass::test #endif // MULTIPASS_COMMON_H
7,122
C++
.h
110
60.381818
120
0.432023
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,030
mock_singleton_helpers.h
canonical_multipass/tests/mock_singleton_helpers.h
/* * 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_SINGLETON_HELPERS_H #define MULTIPASS_MOCK_SINGLETON_HELPERS_H #include "common.h" #include <scope_guard.hpp> #include <cassert> #include <utility> #define MP_MOCK_SINGLETON_INSTANCE(mock_class) \ public: \ static mock_class& mock_instance() \ { \ return dynamic_cast<mock_class&>(instance()); \ } #define MP_MOCK_SINGLETON_HELPER_TYPES(mock_class, parent_class) \ private: \ static constexpr auto academy = [] { \ return sg::make_scope_guard([]() noexcept { parent_class::reset(); }); \ }; /* Produces "guards" :) Use a lambda so that the type gets deduced before decltype below */ \ \ public: \ using Guard = decltype(academy()); \ using GuardedMock = std::pair<mock_class*, Guard>; #define MP_MOCK_SINGLETON_INJECT(mock_class, parent_class) \ public: \ template <template <typename /*MockClass*/> typename MockCharacter = ::testing::NaggyMock> \ [[nodiscard]] static GuardedMock inject() \ { \ parent_class::reset(); \ parent_class::mock<MockCharacter<mock_class>>(); \ return std::make_pair(&mock_instance(), academy()); \ } // one at a time, please! #define MP_MOCK_SINGLETON_BOILERPLATE(mock_class, parent_class) \ public: \ MP_MOCK_SINGLETON_HELPER_TYPES(mock_class, parent_class) \ MP_MOCK_SINGLETON_INSTANCE(mock_class) \ MP_MOCK_SINGLETON_INJECT(mock_class, parent_class) \ void please_dont_call_this_undefined_method_that_gobbles_semicolons() // see https://godbolt.org/z/7ac1zaGxr namespace multipass::test { template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter = ::testing::NaggyMock> class MockSingletonHelper : public ::testing::Environment { public: static void mockit(); void SetUp() override; void TearDown() override; private: class Accountant : public ::testing::EmptyTestEventListener { public: void OnTestEnd(const ::testing::TestInfo&) override; }; void register_accountant(); void release_accountant(); Accountant* accountant = nullptr; // non-owning ptr }; } // namespace multipass::test template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::mockit() { ::testing::AddGlobalTestEnvironment( new MockSingletonHelper<ConcreteMock, MockCharacter>{}); // takes pointer ownership o_O } template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::SetUp() { ConcreteMock::template mock<MockCharacter<ConcreteMock>>(); // Register mock as the singleton instance auto& mock = ConcreteMock::mock_instance(); mock.setup_mock_defaults(); // setup any custom actions for calls on the mock register_accountant(); // register a test observer to verify and clear mock expectations } template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::TearDown() { release_accountant(); // release this mock's test observer ConcreteMock::reset(); /* Make sure this runs before gtest unwinds, so that: - the mock doesn't leak - expectations are checked - it doesn't refer to stuff that was already deleted */ } template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::register_accountant() { accountant = new Accountant{}; ::testing::UnitTest::GetInstance()->listeners().Append(accountant); // takes ownership } template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::release_accountant() { [[maybe_unused]] auto* listener = ::testing::UnitTest::GetInstance()->listeners().Release(accountant); // releases ownership assert(listener == accountant); delete accountant; // no prob if already null accountant = nullptr; } template <typename ConcreteMock, template <typename /*MockClass*/> typename MockCharacter> void multipass::test::MockSingletonHelper<ConcreteMock, MockCharacter>::Accountant::OnTestEnd( const ::testing::TestInfo& /*unused*/) { ::testing::Mock::VerifyAndClearExpectations(&ConcreteMock::mock_instance()); } #endif // MULTIPASS_MOCK_SINGLETON_HELPERS_H
7,228
C++
.h
117
56.752137
120
0.522714
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,031
mock_ssh_client.h
canonical_multipass/tests/mock_ssh_client.h
/* * 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_SSH_CLIENT #define MULTIPASS_MOCK_SSH_CLIENT #include <premock.hpp> #include <libssh/libssh.h> DECL_MOCK(ssh_channel_request_shell); DECL_MOCK(ssh_channel_request_pty); DECL_MOCK(ssh_channel_change_pty_size); #endif // MULTIPASS_MOCK_SSH_CLIENT
901
C++
.h
24
35.708333
72
0.768349
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,032
image_host_remote_count.h
canonical_multipass/tests/image_host_remote_count.h
/* * 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_IMAGE_HOST_REMOTE_COUNT_H #define MULTIPASS_IMAGE_HOST_REMOTE_COUNT_H #include <cstddef> namespace multipass { class VMImageHost; namespace test { size_t count_remotes(VMImageHost& host); } } // namespace multipass #endif /* MULTIPASS_IMAGE_HOST_REMOTE_COUNT_H */
914
C++
.h
28
30.964286
72
0.769841
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,033
mock_cert_store.h
canonical_multipass/tests/mock_cert_store.h
/* * 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_CERT_STORE_H #define MULTIPASS_MOCK_CERT_STORE_H #include <multipass/cert_store.h> namespace multipass::test { struct MockCertStore : public CertStore { MOCK_METHOD(void, add_cert, (const std::string&), (override)); MOCK_METHOD(std::string, PEM_cert_chain, (), (const, override)); MOCK_METHOD(bool, verify_cert, (const std::string&), (override)); MOCK_METHOD(bool, empty, (), (override)); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_CERT_STORE_H
1,131
C++
.h
30
35.566667
72
0.738616
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,034
stub_terminal.h
canonical_multipass/tests/stub_terminal.h
/* * 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_STUB_TERMINAL_H #define MULTIPASS_STUB_TERMINAL_H #include <multipass/terminal.h> namespace multipass { namespace test { class StubTerminal : public multipass::Terminal { public: StubTerminal(std::ostream& cout, std::ostream& cerr, std::istream& cin) : cout_stream{cout}, cerr_stream{cerr}, cin_stream{cin} {} ~StubTerminal() override = default; std::istream& cin() override { return cin_stream; } std::ostream& cout() override { return cout_stream; } std::ostream& cerr() override { return cerr_stream; } bool cin_is_live() const override { return false; } bool cout_is_live() const override { return false; } void set_cin_echo(const bool enable) override { } private: std::ostream &cout_stream; std::ostream& cerr_stream; std::istream& cin_stream; }; } // namespace test } // namespace multipass #endif // MULTIPASS_STUB_TERMINAL_H
1,636
C++
.h
61
23.016393
75
0.695457
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,035
reset_process_factory.h
canonical_multipass/tests/reset_process_factory.h
/* * 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_RESETTABLE_PROCESS_FACTORY_H #define MULTIPASS_RESETTABLE_PROCESS_FACTORY_H #include "process_factory.h" // rely on build system to include the right implementation namespace multipass { namespace test { // This resets the ProcessFactory on creation & destruction struct ResetProcessFactory { ResetProcessFactory(); ~ResetProcessFactory(); }; } // namespace test } // namespace multipass #endif // MULTIPASS_RESETTABLE_PROCESS_FACTORY_H
1,097
C++
.h
32
32.375
88
0.777148
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,036
stub_snapshot.h
canonical_multipass/tests/stub_snapshot.h
/* * 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_STUB_SNAPSHOT_H #define MULTIPASS_STUB_SNAPSHOT_H #include <multipass/memory_size.h> #include <multipass/snapshot.h> #include <QJsonObject> namespace multipass::test { struct StubSnapshot : public Snapshot { std::string get_name() const noexcept override { return {}; } std::string get_comment() const noexcept override { return {}; } std::string get_cloud_init_instance_id() const noexcept override { return {}; } QDateTime get_creation_timestamp() const noexcept override { return QDateTime{}; } std::string get_parents_name() const override { return {}; } std::shared_ptr<const Snapshot> get_parent() const noexcept override { return nullptr; } std::shared_ptr<Snapshot> get_parent() override { return nullptr; } int get_index() const noexcept override { return 0; } int get_parents_index() const override { return 0; } int get_num_cores() const noexcept override { return 0; } MemorySize get_mem_size() const noexcept override { return MemorySize{}; } MemorySize get_disk_space() const noexcept override { return MemorySize{}; } std::vector<NetworkInterface> get_extra_interfaces() const noexcept override { return std::vector<NetworkInterface>{}; } VirtualMachine::State get_state() const noexcept override { return VirtualMachine::State::off; } const std::unordered_map<std::string, VMMount>& get_mounts() const noexcept override { return mounts; } const QJsonObject& get_metadata() const noexcept override { return metadata; } void set_name(const std::string&) override { } void set_comment(const std::string&) override { } void set_parent(std::shared_ptr<Snapshot>) override { } void capture() override { } void erase() override { } void apply() override { } std::unordered_map<std::string, VMMount> mounts; QJsonObject metadata; }; } // namespace multipass::test #endif // MULTIPASS_STUB_SNAPSHOT_H
2,881
C++
.h
112
20.776786
88
0.666302
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,037
stub_url_downloader.h
canonical_multipass/tests/stub_url_downloader.h
/* * 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_STUB_URL_DOWNLOADER_H #define MULTIPASS_STUB_URL_DOWNLOADER_H #include <multipass/url_downloader.h> namespace multipass { namespace test { struct StubURLDownloader : public multipass::URLDownloader { StubURLDownloader() : multipass::URLDownloader{std::chrono::seconds(10)} { } void download_to(const QUrl& url, const QString& file_name, int64_t size, const int download_type, const multipass::ProgressMonitor&) override { } QByteArray download(const QUrl& url) override { return {}; } }; } // namespace test } // namespace multipass #endif // MULTIPASS_STUB_URL_DOWNLOADER_H
1,289
C++
.h
40
29.15
102
0.735152
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,038
mock_ssh_test_fixture.h
canonical_multipass/tests/mock_ssh_test_fixture.h
/* * 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_SSH_TEST_FIXTURE_H #define MULTIPASS_MOCK_SSH_TEST_FIXTURE_H #include "mock_ssh.h" namespace multipass { namespace test { // This sets up all default values for any libssh API calls. // Use REPLACE() *after* instantiating this in the test unit to override the default. struct MockSSHTestFixture { MockSSHTestFixture() { connect.returnValue(SSH_OK); is_connected.returnValue(true); open_session.returnValue(SSH_OK); userauth_publickey.returnValue(SSH_OK); request_exec.returnValue(SSH_OK); channel_read.returnValue(0); is_eof.returnValue(true); get_exit_status.returnValue(SSH_OK); channel_is_open.returnValue(true); channel_is_closed.returnValue(0); options_set.returnValue(SSH_OK); } decltype(MOCK(ssh_connect)) connect{MOCK(ssh_connect)}; decltype(MOCK(ssh_is_connected)) is_connected{MOCK(ssh_is_connected)}; decltype(MOCK(ssh_channel_open_session)) open_session{MOCK(ssh_channel_open_session)}; decltype(MOCK(ssh_userauth_publickey)) userauth_publickey{MOCK(ssh_userauth_publickey)}; decltype(MOCK(ssh_channel_request_exec)) request_exec{MOCK(ssh_channel_request_exec)}; decltype(MOCK(ssh_channel_read_timeout)) channel_read{MOCK(ssh_channel_read_timeout)}; decltype(MOCK(ssh_channel_is_eof)) is_eof{MOCK(ssh_channel_is_eof)}; decltype(MOCK(ssh_channel_get_exit_status)) get_exit_status{MOCK(ssh_channel_get_exit_status)}; decltype(MOCK(ssh_channel_is_open)) channel_is_open{MOCK(ssh_channel_is_open)}; decltype(MOCK(ssh_channel_is_closed)) channel_is_closed{MOCK(ssh_channel_is_closed)}; decltype(MOCK(ssh_options_set)) options_set{MOCK(ssh_options_set)}; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_SSH_TEST_FIXTURE_H
2,452
C++
.h
56
39.875
99
0.737876
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,039
mock_sftp_client.h
canonical_multipass/tests/mock_sftp_client.h
/* * 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 MOCK_SFTP_CLIENT_H #define MOCK_SFTP_CLIENT_H #include "common.h" #include <multipass/ssh/sftp_client.h> namespace multipass::test { struct MockSFTPClient : public SFTPClient { MOCK_METHOD(bool, is_remote_dir, (const fs::path& path), (override)); MOCK_METHOD(bool, push, (const fs::path& source_path, const fs::path& target_path, Flags flags), (override)); MOCK_METHOD(bool, pull, (const fs::path& source_path, const fs::path& target_path, Flags flags), (override)); MOCK_METHOD(void, from_cin, (std::istream & cin, const fs::path& target_path, bool make_parent), (override)); MOCK_METHOD(void, to_cout, (const fs::path& source_path, std::ostream& cout), (override)); }; } // namespace multipass::test #endif // MOCK_SFTP_CLIENT_H
1,391
C++
.h
32
41.25
113
0.731365
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,040
mock_ssh.h
canonical_multipass/tests/mock_ssh.h
/* * 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_SSH_H #define MULTIPASS_MOCK_SSH_H #include <premock.hpp> #include <libssh/callbacks.h> #include <libssh/libssh.h> DECL_MOCK(ssh_new); DECL_MOCK(ssh_connect); DECL_MOCK(ssh_is_connected); DECL_MOCK(ssh_options_set); DECL_MOCK(ssh_userauth_publickey); DECL_MOCK(ssh_channel_is_eof); DECL_MOCK(ssh_channel_is_closed); DECL_MOCK(ssh_channel_is_open); DECL_MOCK(ssh_channel_new); DECL_MOCK(ssh_channel_open_session); DECL_MOCK(ssh_channel_request_exec); DECL_MOCK(ssh_channel_read_timeout); DECL_MOCK(ssh_channel_get_exit_status); DECL_MOCK(ssh_event_dopoll); DECL_MOCK(ssh_add_channel_callbacks); DECL_MOCK(ssh_get_error); #endif // MULTIPASS_MOCK_SSH_H
1,307
C++
.h
38
32.868421
72
0.771361
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,041
sftp_server_test_fixture.h
canonical_multipass/tests/sftp_server_test_fixture.h
/* * 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_SFTP_SERVER_TEST_FIXTURE_H #define MULTIPASS_SFTP_SERVER_TEST_FIXTURE_H #include "common.h" #include "mock_sftp.h" #include "mock_sftpserver.h" #include "mock_ssh_test_fixture.h" namespace multipass { namespace test { struct SftpServerTest : public testing::Test { SftpServerTest() : free_sftp{mock_sftp_free, [](sftp_session sftp) { std::free(sftp->handles); std::free(sftp); }} { init_sftp.returnValue(SSH_OK); reply_status.returnValue(SSH_OK); get_client_msg.returnValue(nullptr); handle_sftp.returnValue(nullptr); } decltype(MOCK(sftp_server_init)) init_sftp{MOCK(sftp_server_init)}; decltype(MOCK(sftp_reply_status)) reply_status{MOCK(sftp_reply_status)}; decltype(MOCK(sftp_get_client_message)) get_client_msg{MOCK(sftp_get_client_message)}; decltype(MOCK(sftp_client_message_free)) msg_free{MOCK(sftp_client_message_free)}; decltype(MOCK(sftp_handle)) handle_sftp{MOCK(sftp_handle)}; MockScope<decltype(mock_sftp_free)> free_sftp; MockSSHTestFixture mock_ssh_test_fixture; }; } // namespace test } // namespace multipass #endif // MULTIPASS_SFTP_SERVER_TEST_FIXTURE_H
1,874
C++
.h
50
33.12
90
0.712479
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,042
temp_dir.h
canonical_multipass/tests/temp_dir.h
/* * 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_TEMP_DIR_H #define MULTIPASS_TEMP_DIR_H #include <QString> #include <QTemporaryDir> namespace multipass { namespace test { class TempDir { public: TempDir(); QString path() const { return the_path; } QString filePath(const QString& fileName) { return dir.filePath(fileName); } private: QTemporaryDir dir; QString the_path; }; } // namespace test } // namespace multipass #endif // MULTIPASS_TEMP_DIR_H
1,106
C++
.h
43
23.023256
72
0.734153
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,043
stub_mount_handler.h
canonical_multipass/tests/stub_mount_handler.h
/* * 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_STUB_MOUNT_HANDLER #define MULTIPASS_STUB_MOUNT_HANDLER #include <multipass/mount_handler.h> namespace multipass::test { struct StubMountHandler : public MountHandler { void activate_impl(ServerVariant, std::chrono::milliseconds) override { } void deactivate_impl(bool) override { } }; } // namespace multipass::test #endif // MULTIPASS_STUB_MOUNT_HANDLER
1,030
C++
.h
32
29.84375
73
0.758551
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,044
mock_snapshot.h
canonical_multipass/tests/mock_snapshot.h
/* * 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(std::string, get_cloud_init_instance_id, (), (const, noexcept, 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(std::vector<mp::NetworkInterface>, get_extra_interfaces, (), (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
2,633
C++
.h
52
47.538462
116
0.705243
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,045
mock_sftpserver.h
canonical_multipass/tests/mock_sftpserver.h
/* * 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_SFTPSERVER_H #define MULTIPASS_MOCK_SFTPSERVER_H #include <premock.hpp> #include <libssh/sftp.h> DECL_MOCK(sftp_server_new); DECL_MOCK(sftp_server_init); DECL_MOCK(sftp_reply_status); DECL_MOCK(sftp_reply_attr); DECL_MOCK(sftp_reply_data); DECL_MOCK(sftp_reply_name); DECL_MOCK(sftp_reply_names); DECL_MOCK(sftp_reply_names_add); DECL_MOCK(sftp_reply_handle); DECL_MOCK(sftp_get_client_message); DECL_MOCK(sftp_client_message_free); DECL_MOCK(sftp_client_message_get_data); DECL_MOCK(sftp_client_message_get_filename); DECL_MOCK(sftp_handle); DECL_MOCK(sftp_handle_alloc); DECL_MOCK(sftp_handle_remove); #endif // MULTIPASS_MOCK_SFTPSERVER_H
1,298
C++
.h
37
33.540541
72
0.775478
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,046
mock_openssl_syscalls.h
canonical_multipass/tests/mock_openssl_syscalls.h
/* * 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_OPENSSL_SYSCALLS_H #define MULTIPASS_MOCK_OPENSSL_SYSCALLS_H #include <premock.hpp> #include <openssl/evp.h> DECL_MOCK(EVP_PBE_scrypt); #endif // MULTIPASS_MOCK_OPENSSL_SYSCALLS_H
836
C++
.h
22
36.090909
72
0.766378
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,047
mock_environment_helpers.h
canonical_multipass/tests/mock_environment_helpers.h
/* * 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_ENVIRONMENT_HELPER_H #define MULTIPASS_MOCK_ENVIRONMENT_HELPER_H #include <QByteArray> namespace multipass { namespace test { class SetEnvScope { public: explicit SetEnvScope(const QByteArray& name, const QByteArray& new_value) : name(name), old_value{qgetenv(name.constData())} { qputenv(name.constData(), new_value); } ~SetEnvScope() { if (old_value.isNull()) qunsetenv(name.constData()); else qputenv(name.constData(), old_value); } private: QByteArray name, old_value; }; class UnsetEnvScope { public: explicit UnsetEnvScope(const QByteArray& name) : name(name) { old_value = qgetenv(name.constData()); if (!old_value.isNull()) qunsetenv(name.constData()); } ~UnsetEnvScope() { if (!old_value.isNull()) qputenv(name.constData(), old_value); } private: QByteArray name, old_value; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_ENVIRONMENT_HELPER_H
1,699
C++
.h
61
23.819672
77
0.694717
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,048
mock_cloud_init_file_ops.h
canonical_multipass/tests/mock_cloud_init_file_ops.h
/* * 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_CLOUD_INIT_FILE_OPS_H #define MULTIPASS_MOCK_CLOUD_INIT_FILE_OPS_H #include "mock_singleton_helpers.h" #include <multipass/cloud_init_iso.h> namespace multipass::test { class MockCloudInitFileOps : public CloudInitFileOps { public: using CloudInitFileOps::CloudInitFileOps; MOCK_METHOD( void, update_cloud_init_with_new_extra_interfaces_and_new_id, (const std::string&, const std::vector<NetworkInterface>&, const std::string&, const std::filesystem::path&), (const, override)); MOCK_METHOD( void, update_cloned_cloud_init_unique_identifiers, (const std::string&, const std::vector<NetworkInterface>&, const std::string&, const std::filesystem::path&), (const, override)); MOCK_METHOD(void, add_extra_interface_to_cloud_init, (const std::string&, const NetworkInterface&, const std::filesystem::path&), (const, override)); MOCK_METHOD(std::string, get_instance_id_from_cloud_init, (const std::filesystem::path&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockCloudInitFileOps, CloudInitFileOps); }; } // namespace multipass::test #endif // MULTIPASS_MOCK_CLOUD_INIT_FILE_OPS_H
1,879
C++
.h
45
37.244444
117
0.717022
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,049
mock_virtual_machine.h
canonical_multipass/tests/mock_virtual_machine.h
/* * 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_VIRTUAL_MACHINE_H #define MULTIPASS_MOCK_VIRTUAL_MACHINE_H #include "common.h" #include "temp_dir.h" #include <multipass/memory_size.h> #include <multipass/mount_handler.h> #include <multipass/virtual_machine.h> #include <memory> using namespace testing; namespace multipass { namespace test { template <typename T = VirtualMachine, typename = std::enable_if_t<std::is_base_of_v<VirtualMachine, T>>> struct MockVirtualMachineT : public T { template <typename... Args> MockVirtualMachineT(Args&&... args) : MockVirtualMachineT{std::make_unique<TempDir>(), std::forward<Args>(args)...} { } template <typename... Args> MockVirtualMachineT(std::unique_ptr<TempDir>&& tmp_dir, Args&&... args) : 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)); ON_CALL(*this, ssh_hostname()).WillByDefault(Return("localhost")); ON_CALL(*this, ssh_hostname(_)).WillByDefault(Return("localhost")); ON_CALL(*this, ssh_username()).WillByDefault(Return("ubuntu")); ON_CALL(*this, management_ipv4()).WillByDefault(Return("0.0.0.0")); ON_CALL(*this, get_all_ipv4()).WillByDefault(Return(std::vector<std::string>{"192.168.2.123"})); ON_CALL(*this, ipv6()).WillByDefault(Return("::/0")); } MOCK_METHOD(void, start, (), (override)); MOCK_METHOD(void, shutdown, (VirtualMachine::ShutdownPolicy), (override)); MOCK_METHOD(void, suspend, (), (override)); MOCK_METHOD(multipass::VirtualMachine::State, current_state, (), (override)); MOCK_METHOD(int, ssh_port, (), (override)); MOCK_METHOD(std::string, ssh_hostname, (), (override)); MOCK_METHOD(std::string, ssh_hostname, (std::chrono::milliseconds), (override)); MOCK_METHOD(std::string, ssh_username, (), (override)); MOCK_METHOD(std::string, management_ipv4, (), (override)); MOCK_METHOD(std::vector<std::string>, get_all_ipv4, (), (override)); MOCK_METHOD(std::string, ipv6, (), (override)); MOCK_METHOD(std::string, ssh_exec, (const std::string& cmd, bool whisper), (override)); std::string ssh_exec(const std::string& cmd) { return ssh_exec(cmd, false); } MOCK_METHOD(void, ensure_vm_is_running, (), (override)); MOCK_METHOD(void, wait_until_ssh_up, (std::chrono::milliseconds), (override)); MOCK_METHOD(void, wait_for_cloud_init, (std::chrono::milliseconds), (override)); MOCK_METHOD(void, update_state, (), (override)); MOCK_METHOD(void, update_cpus, (int), (override)); MOCK_METHOD(void, resize_memory, (const MemorySize&), (override)); MOCK_METHOD(void, resize_disk, (const MemorySize&), (override)); MOCK_METHOD(void, add_network_interface, (int, const std::string&, const NetworkInterface&), (override)); MOCK_METHOD(std::unique_ptr<MountHandler>, make_native_mount_handler, (const std::string&, const VMMount&), (override)); 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)); MOCK_METHOD(std::shared_ptr<Snapshot>, get_snapshot, (const std::string&), (override)); MOCK_METHOD(std::shared_ptr<Snapshot>, get_snapshot, (int index), (override)); MOCK_METHOD(std::shared_ptr<const Snapshot>, take_snapshot, (const VMSpecs&, const std::string&, const std::string&), (override)); MOCK_METHOD(void, rename_snapshot, (const std::string& old_name, const std::string& new_name), (override)); MOCK_METHOD(void, delete_snapshot, (const std::string& name), (override)); MOCK_METHOD(void, restore_snapshot, (const std::string&, VMSpecs&), (override)); 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)); MOCK_METHOD(void, remove_snapshots_from_image, (), (const override)); std::unique_ptr<TempDir> tmp_dir; }; using MockVirtualMachine = MockVirtualMachineT<>; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_VIRTUAL_MACHINE_H
5,211
C++
.h
100
47.2
119
0.682879
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,050
mock_sftp_dir_iterator.h
canonical_multipass/tests/mock_sftp_dir_iterator.h
/* * 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 MOCK_SFTP_DIR_ITERATOR_H #define MOCK_SFTP_DIR_ITERATOR_H #include "common.h" #include <multipass/ssh/sftp_dir_iterator.h> namespace multipass::test { struct MockSFTPDirIterator : public SFTPDirIterator { MOCK_METHOD(bool, hasNext, (), (override, const)); MOCK_METHOD(SFTPAttributesUPtr, next, (), (override)); }; } // namespace multipass::test #endif // MOCK_SFTP_DIR_ITERATOR_H
1,027
C++
.h
29
33.517241
72
0.754774
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,051
mock_aa_syscalls.h
canonical_multipass/tests/linux/mock_aa_syscalls.h
/* * 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_AA_SYSCALLS_H #define MULTIPASS_MOCK_AA_SYSCALLS_H #include <premock.hpp> #include <sys/apparmor.h> DECL_MOCK(aa_is_enabled); #endif // MULTIPASS_MOCK_AA_SYSCALLS_H
821
C++
.h
22
35.409091
72
0.761965
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,052
mock_q_buffer.h
canonical_multipass/tests/linux/mock_q_buffer.h
/* * 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_Q_BUFFER_H #define MULTIPASS_MOCK_Q_BUFFER_H #include <QBuffer> namespace multipass { namespace test { class MockQBuffer : public QBuffer { public: MockQBuffer(QByteArray* byteArray) : QBuffer(byteArray){}; virtual qint64 readData(char* data, qint64 len) override { read_called = true; return -1; }; bool read_attempted() { return read_called; } private: bool read_called{false}; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_Q_BUFFER_H
1,179
C++
.h
42
25.190476
72
0.729849
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,053
mock_q_local_socket.h
canonical_multipass/tests/linux/mock_q_local_socket.h
/* * 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_Q_LOCAL_SOCKET_H #define MULTIPASS_MOCK_Q_LOCAL_SOCKET_H #include <QLocalSocket> namespace multipass { namespace test { class MockQLocalSocket : public QLocalSocket { public: MockQLocalSocket(int writes_before_failure) : writes_before_failure{writes_before_failure} { QIODevice::open(QIODevice::ReadWrite); }; virtual qint64 writeData(const char* data, qint64 c) override { ++num_writes; if (writes_before_failure-- > 0) return c; else return -1; }; virtual bool waitForBytesWritten(int msecs = 30000) override { return true; }; int num_writes_called() { return num_writes; }; private: int writes_before_failure; int num_writes{0}; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_Q_LOCAL_SOCKET_H
1,510
C++
.h
53
24.622642
94
0.707182
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,054
local_socket_server_test_fixture.h
canonical_multipass/tests/linux/local_socket_server_test_fixture.h
/* * 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_LOCAL_SOCKET_SERVER_TEST_FIXTURE_H #define MULTIPASS_LOCAL_SOCKET_SERVER_TEST_FIXTURE_H #include <QByteArray> #include <QLocalServer> #include <QLocalSocket> #include <QString> namespace multipass { namespace test { class MockLocalSocketServer { public: MockLocalSocketServer(const QString& socket_path) { test_server.listen(socket_path); } template <typename Handler> void local_socket_server_handler(Handler&& response_handler) { QObject::connect(&test_server, &QLocalServer::newConnection, [&] { auto client_connection = test_server.nextPendingConnection(); client_connection->waitForReadyRead(); auto data = client_connection->readAll(); auto response = response_handler(data); // Simulate data arriving in chunks int left = response.length() / 2; client_connection->write(response.left(left)); client_connection->flush(); client_connection->write(response.right(response.length() - left)); client_connection->close(); }); } private: QLocalServer test_server; }; } // namespace test } // namespace multipass #endif /* MULTIPASS_LOCAL_SOCKET_SERVER_TEST_FIXTURE_H */
1,901
C++
.h
55
29.927273
79
0.70822
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,055
mock_qemu_platform.h
canonical_multipass/tests/qemu/mock_qemu_platform.h
/* * 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_QEMU_PLATFORM_H #define MULTIPASS_MOCK_QEMU_PLATFORM_H #include "tests/common.h" #include "tests/mock_singleton_helpers.h" #include <src/platform/backends/qemu/qemu_platform.h> namespace multipass { namespace test { struct MockQemuPlatform : public QemuPlatform { MockQemuPlatform() { EXPECT_CALL(*this, vmstate_platform_args()) .Times(testing::AnyNumber()) .WillRepeatedly(testing::Return(QStringList())); } MOCK_METHOD(std::optional<IPAddress>, get_ip_for, (const std::string&), (override)); MOCK_METHOD(void, remove_resources_for, (const std::string&), (override)); MOCK_METHOD(void, platform_health_check, (), (override)); MOCK_METHOD(QStringList, vmstate_platform_args, (), (override)); MOCK_METHOD(QStringList, vm_platform_args, (const VirtualMachineDescription&), (override)); MOCK_METHOD(QString, get_directory_name, (), (const, override)); MOCK_METHOD(bool, is_network_supported, (const std::string&), (const, override)); MOCK_METHOD(bool, needs_network_prep, (), (const override)); MOCK_METHOD(std::string, create_bridge_with, (const NetworkInterfaceInfo&), (const, override)); MOCK_METHOD(void, set_authorization, (std::vector<NetworkInterfaceInfo>&), (override)); }; struct MockQemuPlatformFactory : public QemuPlatformFactory { using QemuPlatformFactory::QemuPlatformFactory; MOCK_METHOD(QemuPlatform::UPtr, make_qemu_platform, (const Path&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockQemuPlatformFactory, QemuPlatformFactory); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_QEMU_PLATFORM
2,295
C++
.h
53
40.056604
99
0.739928
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,056
mock_firewall_config.h
canonical_multipass/tests/qemu/linux/mock_firewall_config.h
/* * 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_FIREWALL_CONFIG #define MULTIPASS_MOCK_FIREWALL_CONFIG #include "tests/common.h" #include "tests/mock_singleton_helpers.h" #include <src/platform/backends/qemu/linux/firewall_config.h> namespace multipass { namespace test { struct MockFirewallConfig : public FirewallConfig { using FirewallConfig::FirewallConfig; MOCK_METHOD(void, verify_firewall_rules, (), (override)); }; struct MockFirewallConfigFactory : public FirewallConfigFactory { using FirewallConfigFactory::FirewallConfigFactory; MOCK_METHOD(FirewallConfig::UPtr, make_firewall_config, (const QString&, const std::string&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockFirewallConfigFactory, FirewallConfigFactory); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_FIREWALL_CONFIG
1,456
C++
.h
39
35.230769
117
0.782825
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,057
mock_dnsmasq_server.h
canonical_multipass/tests/qemu/linux/mock_dnsmasq_server.h
/* * 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_DNSMASQ_SERVER_H #define MULTIPASS_MOCK_DNSMASQ_SERVER_H #include "tests/common.h" #include "tests/mock_singleton_helpers.h" #include <src/platform/backends/qemu/linux/dnsmasq_server.h> namespace multipass { namespace test { struct MockDNSMasqServer : public DNSMasqServer { using DNSMasqServer::DNSMasqServer; // ctor MOCK_METHOD(std::optional<IPAddress>, get_ip_for, (const std::string&), (override)); MOCK_METHOD(void, release_mac, (const std::string&), (override)); MOCK_METHOD(void, check_dnsmasq_running, (), (override)); }; struct MockDNSMasqServerFactory : public DNSMasqServerFactory { using DNSMasqServerFactory::DNSMasqServerFactory; MOCK_METHOD(DNSMasqServer::UPtr, make_dnsmasq_server, (const Path&, const QString&, const std::string&), (const, override)); MP_MOCK_SINGLETON_BOILERPLATE(MockDNSMasqServerFactory, DNSMasqServerFactory); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_DNSMASQ_SERVER_H
1,642
C++
.h
42
36.5
108
0.759422
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,058
mock_lxd_server_responses.h
canonical_multipass/tests/lxd/mock_lxd_server_responses.h
/* * 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_LXD_SERVER_RESPONSES_H #define MULTIPASS_MOCK_LXD_SERVER_RESPONSES_H #include <QByteArray> namespace multipass { namespace test { const QByteArray not_found_data{"{\"error\": \"not found\",\"error_code\": 404,\"type\": \"error\"}"}; const QByteArray post_no_error_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": null," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray project_info_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"config\": {" " \"features.images\": \"true\"," " \"features.profiles\": \"true\"," " \"features.storage.volumes\": \"true\"" " }," " \"description\": \"Project for Multipass instances\"," " \"name\": \"multipass\"," " \"used_by\": [" " \"/1.0/profiles/default?project=multipass\"" " ]" "}," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray network_info_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"config\": {" " \"ipv4.address\": \"10.241.212.1/24\"," " \"ipv4.nat\": \"true\"," " \"ipv6.address\": \"fd42:cc44:a223:7956::1/64\"," " \"ipv6.nat\": \"true\"" " }," " \"description\": \"Network bridge for Multipass\"," " \"locations\": [" " \"none\"" " ]," " \"managed\": true," " \"name\": \"mpbr0\"," " \"status\": \"Created\"," " \"type\": \"bridge\"," " \"used_by\": [" " ]" "}," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray create_vm_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-05-18T15:14:21.104580212-04:00\"," " \"description\": \"Creating container\"," " \"err\": \"\"," " \"id\": \"0020444c-2e4c-49d5-83ed-3275e3f6d005\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": {" " \"containers\": [" " \"/1.0/containers/pied-piper-valley\"" " ]," " \"instances\": [" " \"/1.0/instances/pied-piper-valley\"" " ]" " }," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-05-18T15:14:21.104580212-04:00\"" " }," "\"operation\": \"/1.0/operations/0020444c-2e4c-49d5-83ed-3275e3f6d005\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}\n"}; const QByteArray create_vm_finished_data{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-05-18T15:14:21.104580212-04:00\"," " \"description\": \"Creating container\"," " \"err\": \"\"," " \"id\": \"0020444c-2e4c-49d5-83ed-3275e3f6d005\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": {" " \"create_instance_from_image_unpack_progress\": \"Unpack: 100% (2.18GB/s)\"," " \"progress\": {" " \"percent\": \"100\"," " \"speed\": \"2184873949\"," " \"stage\": \"create_instance_from_image_unpack\"" " }" " }," " \"resources\": {" " \"containers\": [" " \"/1.0/containers/pied-piper-valley\"" " ]," " \"instances\": [" " \"/1.0/instances/pied-piper-valley\"" " ]" " }," " \"status\": \"Success\"," " \"status_code\": 200," " \"updated_at\": \"2020-05-18T15:14:21.104580212-04:00\"" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_info_data{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"architecture\": \"x86_64\"," " \"config\": {" " \"image.architecture\": \"amd64\"," " \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\"," " \"image.label\": \"release\"," " \"image.os\": \"ubuntu\"," " \"image.release\": \"bionic\"," " \"image.serial\": \"20200506\"," " \"image.type\": \"disk1.img\"," " \"image.version\": \"18.04\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"user.meta-data\": \"#cloud-config\ninstance-id: vm1\nlocal-hostname: vm1\ncloud-name: multipass\n\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"created_at\": \"2020-05-13T15:31:46.194594923-04:00\"," " \"description\": \"\"," " \"devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"ephemeral\": false," " \"expanded_config\": {" " \"image.architecture\": \"amd64\"," " \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\"," " \"image.label\": \"release\"," " \"image.os\": \"ubuntu\"," " \"image.release\": \"bionic\"," " \"image.serial\": \"20200506\"," " \"image.type\": \"disk1.img\"," " \"image.version\": \"18.04\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"expanded_devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"eth0\": {" " \"name\": \"eth0\"," " \"nictype\": \"bridged\"," " \"parent\": \"lxdbr0\"," " \"type\": \"nic\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"last_used_at\": \"2020-05-13T15:34:22.934800001-04:00\"," " \"location\": \"none\"," " \"name\": \"pied-piper-valley\"," " \"profiles\": [" " \"default\"" " ]," " \"stateful\": false," " \"status\": \"Stopped\"," " \"status_code\": 102," " \"type\": \"virtual-machine\"" " }," " \"operation\": \"\"," " \"status\": \"Success\"," " \"status_code\": 200," " \"type\": \"sync\"" "}\n"}; const QByteArray vm_info_data_with_image_release{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"architecture\": \"x86_64\"," " \"config\": {" " \"image.architecture\": \"amd64\"," " \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\"," " \"image.label\": \"release\"," " \"image.os\": \"ubuntu\"," " \"image.release\": \"bionic\"," " \"image.release_title\": \"Fake Title\"," // This is to ensure this is what is used in the test " \"image.serial\": \"20200506\"," " \"image.type\": \"disk1.img\"," " \"image.version\": \"18.04\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"created_at\": \"2020-05-13T15:31:46.194594923-04:00\"," " \"description\": \"\"," " \"devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"ephemeral\": false," " \"expanded_config\": {" " \"image.architecture\": \"amd64\"," " \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\"," " \"image.label\": \"release\"," " \"image.os\": \"ubuntu\"," " \"image.release\": \"bionic\"," " \"image.release_title\": \"Fake Title\"," // This is to ensure this is what is used in the test " \"image.serial\": \"20200506\"," " \"image.type\": \"disk1.img\"," " \"image.version\": \"18.04\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"expanded_devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"eth0\": {" " \"name\": \"eth0\"," " \"nictype\": \"bridged\"," " \"parent\": \"lxdbr0\"," " \"type\": \"nic\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"last_used_at\": \"2020-05-13T15:34:22.934800001-04:00\"," " \"location\": \"none\"," " \"name\": \"pied-piper-valley\"," " \"profiles\": [" " \"default\"" " ]," " \"stateful\": false," " \"status\": \"Stopped\"," " \"status_code\": 102," " \"type\": \"virtual-machine\"" " }," " \"operation\": \"\"," " \"status\": \"Success\"," " \"status_code\": 200," " \"type\": \"sync\"" "}\n"}; const QByteArray vm_custom_info_data{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"architecture\": \"x86_64\"," " \"config\": {" " \"image.description\": \"Snapcraft builder for Core 20\"," " \"image.original_hash\": \"6937ddd3f4c3329182855843571fc91ae4fee24e8e0eb0f7cdcf2c22feed4dab\"," " \"image.os\": \"\"," " \"image.release\": \"snapcraft-core20\"," " \"image.version\": \"20200923\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"created_at\": \"2020-05-13T15:31:46.194594923-04:00\"," " \"description\": \"\"," " \"devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"ephemeral\": false," " \"expanded_config\": {" " \"image.description\": \"Snapcraft builder for Core 20\"," " \"image.original_hash\": \"6937ddd3f4c3329182855843571fc91ae4fee24e8e0eb0f7cdcf2c22feed4dab\"," " \"image.os\": \"\"," " \"image.release\": \"snapcraft-core20\"," " \"image.version\": \"20200923\"," " \"limits.cpu\": \"2\"," " \"limits.memory\": \"3221225472\"," " \"volatile.apply_template\": \"create\"," " \"volatile.base_image\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\"" " }," " \"expanded_devices\": {" " \"config\": {" " \"source\": \"cloud-init:config\"," " \"type\": \"disk\"" " }," " \"eth0\": {" " \"name\": \"eth0\"," " \"nictype\": \"bridged\"," " \"parent\": \"lxdbr0\"," " \"type\": \"nic\"" " }," " \"root\": {" " \"path\": \"/\"," " \"pool\": \"default\"," " \"size\": \"16106127360\"," " \"type\": \"disk\"" " }" " }," " \"last_used_at\": \"2020-05-13T15:34:22.934800001-04:00\"," " \"location\": \"none\"," " \"name\": \"pied-piper-valley\"," " \"profiles\": [" " \"default\"" " ]," " \"stateful\": false," " \"status\": \"Stopped\"," " \"status_code\": 102," " \"type\": \"virtual-machine\"" " }," " \"operation\": \"\"," " \"status\": \"Success\"," " \"status_code\": 200," " \"type\": \"sync\"" "}\n"}; const QByteArray start_vm_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-05-19T11:17:20.979902453-04:00\"," " \"description\": \"Starting container\"," " \"err\": \"\"," " \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": {" " \"containers\": [" " \"/1.0/containers/pied-piper-valley\"" " ]" " }," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-05-19T11:17:20.979902453-04:00\"" " }," "\"operation\": \"/1.0/operations/b043d632-5c48-44b3-983c-a25660d61164\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}\n"}; const QByteArray stop_vm_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-05-19T11:17:20.979902453-04:00\"," " \"description\": \"Stopping container\"," " \"err\": \"\"," " \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": {" " \"containers\": [" " \"/1.0/containers/pied-piper-valley\"" " ]" " }," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-05-19T11:17:20.979902453-04:00\"" " }," "\"operation\": \"/1.0/operations/b043d632-5c48-44b3-983c-a25660d61164\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}\n"}; const QByteArray vm_state_stopped_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Stopped\"," " \"status_code\": 102" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_starting_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Starting\"," " \"status_code\": 106" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_freezing_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Freezing\"," " \"status_code\": 109" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_frozen_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Frozen\"," " \"status_code\": 110" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_error_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Error\"," " \"status_code\": 112" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_cancelling_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Cancelling\"," " \"status_code\": 104" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_other_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Bogus\"," " \"status_code\": 115" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_fully_running_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": {" " \"root\": {" " \"usage\": 100352" " }" " }," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": {" " \"eth0\": {" " \"addresses\": [" " {" " \"address\": \"10.217.27.168\"," " \"family\": \"inet\"," " \"netmask\": \"24\"," " \"scope\": \"global\"" " }" " ]," " \"counters\": {" " \"bytes_received\": 0," " \"bytes_sent\": 0," " \"packets_received\": 0," " \"packets_sent\": 0" " }," " \"host_name\": \"tape3019389\"," " \"hwaddr\": \"00:16:3e:13:36:01\"," " \"mtu\": 1500," " \"state\": \"up\"," " \"type\": \"broadcast\"" " }" " }," " \"pid\": 1266500," " \"processes\": -1," " \"status\": \"Running\"," " \"status_code\": 103" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_state_partial_running_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"cpu\": {" " \"usage\": 0" " }," " \"disk\": null," " \"memory\": {" " \"swap_usage\": 0," " \"swap_usage_peak\": 0," " \"usage\": 0," " \"usage_peak\": 0" " }," " \"network\": null," " \"pid\": 0," " \"processes\": 0," " \"status\": \"Running\"," " \"status_code\": 103" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray vm_stop_wait_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-05-20T10:22:02.684673072-04:00\"," " \"description\": \"Stopping container\"," " \"err\": \"\"," " \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": {" " \"containers\": [" " \"/1.0/containers/pied-piper-valley\"" " ]" " }," " \"status\": \"Success\"," " \"status_code\": 200," " \"updated_at\": \"2020-05-20T10:22:02.684673072-04:00\"" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray delete_vm_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" "\"class\": \"task\"," "\"created_at\": \"2021-05-18T08:48:58.601160908-04:00\"," "\"description\": \"Deleting instance\"," "\"err\": \"\"," "\"id\": \"1c6265fc-8194-4790-9ab0-3225b0479155\"," "\"location\": \"none\"," "\"may_cancel\": false," "\"metadata\": null," "\"resources\": {" "\"instances\": [" "\"/1.0/instances/pied-piper-valley\"" "]" "}," "\"status\": \"Running\"," "\"status_code\": 103," "\"updated_at\": \"2021-05-18T08:48:58.601160908-04:00\"" "}," "\"operation\": \"/1.0/operations/1c6265fc-8194-4790-9ab0-3225b0479155\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}\n"}; const QByteArray delete_vm_wait_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" "\"class\": \"task\"," "\"created_at\": \"2021-05-18T08:48:58.601160908-04:00\"," "\"description\": \"Deleting instance\"," "\"err\": \"\"," "\"id\": \"1c6265fc-8194-4790-9ab0-3225b0479155\"," "\"location\": \"none\"," "\"may_cancel\": false," "\"metadata\": null," "\"resources\": {" "\"instances\": [" "\"/1.0/instances/pied-piper-valley\"" "]" "}," "\"status\": \"Success\"," "\"status_code\": 200," "\"updated_at\": \"2021-05-18T08:48:58.601160908-04:00\"" "}," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}\n"}; const QByteArray network_leases_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": [" " {" " \"address\": \"10.217.27.168\"," " \"hostname\": \"pied-piper-valley\"," " \"hwaddr\": \"00:16:3e:fe:f2:b9\"," " \"location\": \"none\"," " \"type\": \"dynamic\"" " }" "]," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray network_leases_data_with_others{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": [" " {" " \"address\": \"10.217.27.178\"," " \"hostname\": \"foobar\"," " \"hwaddr\": \"00:11:22:33:44:55\"," " \"location\": \"none\"," " \"type\": \"dynamic\"" " }," " {" " \"address\": \"10.217.27.168\"," " \"hostname\": \"pied-piper-valley\"," " \"hwaddr\": \"00:16:3e:fe:f2:b9\"," " \"location\": \"none\"," " \"type\": \"dynamic\"" " }" "]," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray network_leases_data_with_ipv6{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": [" " {" " \"address\": \"fd42:3454:f77b:1a3e:5054:ff:fefc:b7fb\"," " \"hostname\": \"pied-piper-valley\"," " \"hwaddr\": \"00:16:3e:fe:f2:b9\"," " \"location\": \"none\"," " \"type\": \"dynamic\"" " }," " {" " \"address\": \"10.217.27.168\"," " \"hostname\": \"pied-piper-valley\"," " \"hwaddr\": \"00:16:3e:fe:f2:b9\"," " \"location\": \"none\"," " \"type\": \"dynamic\"" " }" "]," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray network_no_leases_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": [" "]," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray lxd_server_info_data{"{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": {" " \"config\": {}," " \"api_extensions\": [" " ]," " \"api_status\": \"stable\"," " \"api_version\": \"1.0\"," " \"auth\": \"trusted\"," " \"public\": false," " \"auth_methods\": [" " \"tls\"" " ]," " \"environment\": {" " \"addresses\": []," " \"architectures\": [" " \"x86_64\"," " \"i686\"" " ]," " \"certificate\": \"\n\"," " \"certificate_fingerprint\": \"\"," " \"driver\": \"lxc\"," " \"driver_version\": \"4.0.2\"," " \"firewall\": \"xtables\"," " \"kernel\": \"Linux\"," " \"kernel_architecture\": \"x86_64\"," " \"kernel_features\": {" " \"netnsid_getifaddrs\": \"true\"," " \"seccomp_listener\": \"true\"," " \"seccomp_listener_continue\": \"true\"," " \"shiftfs\": \"false\"," " \"uevent_injection\": \"true\"," " \"unpriv_fscaps\": \"true\"" " }," " \"kernel_version\": \"5.4.0-31-generic\"," " \"lxc_features\": {" " \"cgroup2\": \"true\"," " \"mount_injection_file\": \"true\"," " \"network_gateway_device_route\": \"true\"," " \"network_ipvlan\": \"true\"," " \"network_l2proxy\": \"true\"," " \"network_phys_macvlan_mtu\": \"true\"," " \"network_veth_router\": \"true\"," " \"pidfd\": \"true\"," " \"seccomp_notify\": \"true\"" " }," " \"os_name\": \"Ubuntu\"," " \"os_version\": \"20.04\"," " \"project\": \"default\"," " \"server\": \"lxd\"," " \"server_clustered\": false," " \"server_name\": \"shady\"," " \"server_pid\": 842930," " \"server_version\": \"4.1\"," " \"storage\": \"zfs\"," " \"storage_version\": \"0.8.3-1ubuntu12\"" " }" " }" "}"}; const QByteArray image_info_data{ "{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": [" " {" " \"auto_update\": false," " \"properties\": {" " \"architecture\": \"amd64\"," " \"description\": \"ubuntu 18.04 LTS amd64 (release) (20200519.1)\"," " \"label\": \"release\"," " \"os\": \"ubuntu\"," " \"release\": \"bionic\"," " \"serial\": \"20200519.1\"," " \"type\": \"disk1.img\"," " \"version\": \"18.04\"," " \"query.release\": \"bionic\"," " \"query.remote\": \"\"" " }," " \"public\": false," " \"expires_at\": \"2023-04-25T20:00:00-04:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz\"," " \"fingerprint\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"size\": 345572108," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-05-18T20:00:00-04:00\"," " \"last_used_at\": \"2020-06-04T14:25:42.334466315-04:00\"," " \"uploaded_at\": \"2020-06-04T14:25:41.622958476-04:00\"" " }," " {" " \"auto_update\": false," " \"properties\": {" " \"description\": \"Snapcraft builder for Core 20\"," " \"original_hash\": \"c14a2047c6ba57722bc612115b1d44bea4a29ac2212fcc0628c49aa832dba867\"," " \"os\": \"ubuntu\"," " \"release\": \"snapcraft-core20\"," " \"version\": \"20200901\"" " }," " \"public\": false," " \"expires_at\": \"1969-12-31T19:00:00-05:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-20.04-minimal-cloudimg-amd64.img\"," " \"fingerprint\": \"da708063589b9c83dfeaec7049deac82da96f8969b413d1346dc067897e5934b\"," " \"size\": 209004544," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-09-03T14:35:38-04:00\"," " \"last_used_at\": \"2020-09-03T14:35:39.704314884-04:00\"," " \"uploaded_at\": \"2020-09-03T14:35:39.63307276-04:00\"" " }" " ]" "}"}; const QByteArray normal_image_info_data{ "{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": {" " \"auto_update\": false," " \"properties\": {" " \"architecture\": \"amd64\"," " \"description\": \"ubuntu 18.04 LTS amd64 (release) (20200519.1)\"," " \"label\": \"release\"," " \"os\": \"ubuntu\"," " \"release\": \"bionic\"," " \"serial\": \"20200519.1\"," " \"type\": \"disk1.img\"," " \"version\": \"18.04\"" " }," " \"public\": false," " \"expires_at\": \"2023-04-25T20:00:00-04:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz\"," " \"fingerprint\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"size\": 345572108," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-05-18T20:00:00-04:00\"," " \"last_used_at\": \"2020-06-04T14:25:42.334466315-04:00\"," " \"uploaded_at\": \"2020-06-04T14:25:41.622958476-04:00\"" " }" "}"}; const QByteArray large_image_info_data{ "{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": {" " \"auto_update\": false," " \"properties\": {" " \"architecture\": \"amd64\"," " \"description\": \"ubuntu 18.04 LTS amd64 (release) (20200519.1)\"," " \"label\": \"release\"," " \"os\": \"ubuntu\"," " \"release\": \"bionic\"," " \"serial\": \"20200519.1\"," " \"type\": \"disk1.img\"," " \"version\": \"18.04\"" " }," " \"public\": false," " \"expires_at\": \"2023-04-25T20:00:00-04:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz\"," " \"fingerprint\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"size\": 33345572108," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-05-18T20:00:00-04:00\"," " \"last_used_at\": \"2020-06-04T14:25:42.334466315-04:00\"," " \"uploaded_at\": \"2020-06-04T14:25:41.622958476-04:00\"" " }" "}"}; const QByteArray image_info_unused_updated_image{ "{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": [" " {" " \"auto_update\": false," " \"properties\": {" " \"architecture\": \"amd64\"," " \"description\": \"ubuntu 18.04 LTS amd64 (release) (20200519.1)\"," " \"label\": \"release\"," " \"os\": \"ubuntu\"," " \"release\": \"bionic\"," " \"serial\": \"20200519.1\"," " \"type\": \"disk1.img\"," " \"version\": \"18.04\"," " \"query.release\": \"bionic\"," " \"query.remote\": \"\"," " \"last_used_at\": \"2020-06-04T14:25:42.334466315-04:00\"" " }," " \"public\": false," " \"expires_at\": \"2023-04-25T20:00:00-04:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz\"," " \"fingerprint\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"," " \"size\": 345572108," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-05-18T20:00:00-04:00\"," " \"last_used_at\": \"0001-01-01T00:00:00Z\"," " \"uploaded_at\": \"2020-06-04T14:25:41.622958476-04:00\"" " }" " ]" "}"}; const QByteArray image_download_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-06-09T16:30:04.381432577-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"0a19a412-03d0-4118-bee8-a3095f06d4da\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": null," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-06-09T16:30:04.381432577-04:00\"" " }," "\"operation\": \"/1.0/operations/0a19a412-03d0-4118-bee8-a3095f06d4da\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}"}; const QByteArray image_downloading_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-06-09T16:30:04.381432577-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"0a19a412-03d0-4118-bee8-a3095f06d4da\"," " \"location\": \"none\"," " \"may_cancel\": true," " \"metadata\": {" " \"download_progress\": \"rootfs: 25% (4.95MB/s)\"" " }," " \"resources\": null," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-06-09T16:34:06.381754577-04:00\"" " }," "\"operation\": \"/1.0/operations/0a19a412-03d0-4118-bee8-a3095f06d4da\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"async\"" "}"}; const QByteArray image_download_task_complete{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-09-09T15:16:03.185557772-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"0a19a412-03d0-4118-bee8-a3095f06d4da\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": {" " \"fingerprint\": \"aedb5a84aaf2e4e443e090511156366a2800c26cec1b6a46f44d153c4bf04205\"," " \"size\": \"209004544\"" " }," " \"resources\": null," " \"status\": \"Success\"," " \"status_code\": 200," " \"updated_at\": \"2020-09-09T15:16:03.880393648-04:00\"" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray metadata_downloading_task_data{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-06-09T16:30:04.381432577-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"0a19a412-03d0-4118-bee8-a3095f06d4da\"," " \"location\": \"none\"," " \"may_cancel\": true," " \"metadata\": {" " \"download_progress\": \"metadata: 100% (4.95MB/s)\"" " }," " \"resources\": null," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-06-09T16:34:06.381754577-04:00\"" " }," "\"operation\": \"/1.0/operations/0a19a412-03d0-4118-bee8-a3095f06d4da\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"async\"" "}"}; const QByteArray image_info_update_source_info{ "{" "\"type\": \"sync\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"operation\": \"\"," "\"error_code\": 0," "\"error\": \"\"," "\"metadata\": [" " {" " \"auto_update\": false," " \"properties\": {" " \"architecture\": \"amd64\"," " \"description\": \"ubuntu 18.04 LTS amd64 (release) (20200519.1)\"," " \"label\": \"release\"," " \"os\": \"ubuntu\"," " \"release\": \"bionic\"," " \"serial\": \"20200519.1\"," " \"type\": \"disk1.img\"," " \"version\": \"18.04\"," " \"query.release\": \"bionic\"," " \"query.remote\": \"\"" " }," " \"public\": false," " \"expires_at\": \"2023-04-25T20:00:00-04:00\"," " \"profiles\": [" " \"default\"" " ]," " \"aliases\": []," " \"architecture\": \"x86_64\"," " \"cached\": false," " \"filename\": \"ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz\"," " \"fingerprint\": \"aedb5a84aaf2e4e443e090511156366a2800c26cec1b6a46f44d153c4bf04205\"," " \"size\": 345572108," " \"update_source\": {" " \"alias\": \"bionic\"," " \"certificate\": \"\"," " \"protocol\": \"simplestreams\"," " \"server\": \"https://cloud-images.ubuntu.com/releases/\"," " \"image_type\": \"\"" " }," " \"type\": \"virtual-machine\"," " \"created_at\": \"2020-05-18T20:00:00-04:00\"," " \"last_used_at\": \"2020-06-04T14:25:42.334466315-04:00\"," " \"uploaded_at\": \"2020-06-04T14:25:41.622958476-04:00\"" " }" " ]" "}"}; const QByteArray image_delete_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"id\": \"a8aa52ed-f15f-40d5-8159-dc7640c1761e\"," " \"class\": \"task\"," " \"description\": \"Deleting image\"," " \"created_at\": \"2020-07-06T14:14:15.861352463-04:00\"," " \"updated_at\": \"2020-07-06T14:14:15.861352463-04:00\"," " \"status\": \"Running\"," " \"status_code\": 103," " \"resources\": {" " \"images\": [" " \"/1.0/images/468333262bdc\"" " ]" " }," " \"metadata\": null," " \"may_cancel\": false," " \"err\": \"\"," " \"location\": \"none\"" " }," "\"operation\": \"/1.0/operations/a8aa52ed-f15f-40d5-8159-dc7640c1761e\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}"}; const QByteArray image_upload_task_data{"{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-09-09T15:16:03.185557772-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"dcce4fda-aab9-4117-89c1-9f42b8e3f4a8\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": null," " \"resources\": null," " \"status\": \"Running\"," " \"status_code\": 103," " \"updated_at\": \"2020-09-09T15:16:03.185557772-04:00\"" " }," "\"operation\": \"/1.0/operations/dcce4fda-aab9-4117-89c1-9f42b8e3f4a8\"," "\"status\": \"Operation created\"," "\"status_code\": 100," "\"type\": \"async\"" "}"}; const QByteArray image_upload_task_complete_data{ "{" "\"error\": \"\"," "\"error_code\": 0," "\"metadata\": {" " \"class\": \"task\"," " \"created_at\": \"2020-09-09T15:16:03.185557772-04:00\"," " \"description\": \"Downloading image\"," " \"err\": \"\"," " \"id\": \"dcce4fda-aab9-4117-89c1-9f42b8e3f4a8\"," " \"location\": \"none\"," " \"may_cancel\": false," " \"metadata\": {" " \"fingerprint\": \"bc5a973bd6f2bef30658fb51177cf5e506c1d60958a4c97813ee26416dc368da\"," " \"size\": \"209004544\"" " }," " \"resources\": null," " \"status\": \"Success\"," " \"status_code\": 200," " \"updated_at\": \"2020-09-09T15:16:03.880393648-04:00\"" " }," "\"operation\": \"\"," "\"status\": \"Success\"," "\"status_code\": 200," "\"type\": \"sync\"" "}"}; const QByteArray networks_empty_data{R"( { "type": "sync", "status": "Success", "status_code": 200, "operation": "", "error_code": 0, "error": "", "metadata": [] })"}; const QByteArray networks_realistic_data{R"( { "type": "sync", "status": "Success", "status_code": 200, "operation": "", "error_code": 0, "error": "", "metadata": [ { "config": { "ipv4.address": "10.48.127.1/24", "ipv4.nat": "true", "ipv6.address": "fd42:f933:79c:618f::1/64", "ipv6.nat": "true" }, "description": "", "name": "lxdbr0", "type": "bridge", "used_by": [ "/1.0/profiles/default" ], "managed": true, "status": "Created", "locations": [ "none" ] }, { "config": { "ipv4.address": "10.186.122.1/24", "ipv4.nat": "true", "ipv6.address": "fd42:3d5d:5553:7fc8::1/64", "ipv6.nat": "true" }, "description": "Network bridge for Multipass", "name": "mpbr0", "type": "bridge", "used_by": [ "/1.0/profiles/default?project=multipass" ], "managed": true, "status": "Created", "locations": [ "none" ] }, { "config": {}, "description": "", "name": "lo", "type": "loopback", "used_by": [], "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "wlp2s0", "type": "physical", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "virbr0", "type": "bridge", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "virbr0-nic", "type": "unknown", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "enxe4b97a832426", "type": "physical", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "mpqemubr0-dummy", "type": "unknown", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "mpqemubr0", "type": "bridge", "used_by": null, "managed": false, "status": "", "locations": null }, { "config": {}, "description": "", "name": "tap-a1a0e5e916d", "type": "unknown", "used_by": null, "managed": false, "status": "", "locations": null } ] })"}; const QByteArray networks_faulty_data{R"( { "status": "Success", "status_code": 200, "nonsense": "field", "metadata": [ { "type": "bridge", "but": "noname" }, { "name": "virbr0", "type": "bridge" }, { "name": "enxe4b97a832426", "type": "physical" }, { "name": "", "type": "bridge", "but": "empty name" }, { "name": "bla", "but": "notype" }, { "name": "en0", "type": "physical" }, { "name": "lxdbr0", "type": "bridge" }, { "name": 123, "type": "bridge" }, { "name": "eth0", "type": 123 }, { "name": "mpbr0", "type": "bridge" }, { "name": "mpqemubr0", "type": "bridge" }, { "name": "blahh", "type": "unknown" } ] })"}; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_LXD_SERVER_RESPONSES_H
71,558
C++
.h
1,517
25.932762
119
0.286467
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,059
mock_local_socket_reply.h
canonical_multipass/tests/lxd/mock_local_socket_reply.h
/* * 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_LOCAL_SOCKET_REPLY_H #define MULTIPASS_MOCK_LOCAL_SOCKET_REPLY_H #include <src/network/local_socket_reply.h> namespace multipass { namespace test { struct MockLocalSocketReply : public LocalSocketReply { MockLocalSocketReply(const QByteArray& data, const QNetworkReply::NetworkError error = QNetworkReply::NoError) { content_data = data; setError(error, "Error"); }; // Needed since setFinished is protected in QNetworkReply void setFinished(bool finished) { QNetworkReply::setFinished(finished); }; }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_LOCAL_SOCKET_REPLY_H
1,302
C++
.h
39
30.538462
114
0.751987
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,060
mock_network_access_manager.h
canonical_multipass/tests/lxd/mock_network_access_manager.h
/* * 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_NETWORK_ACCESS_MANAGER_H #define MULTIPASS_MOCK_NETWORK_ACCESS_MANAGER_H #include "mock_local_socket_reply.h" #include "tests/common.h" #include <multipass/network_access_manager.h> using namespace testing; namespace multipass { namespace test { struct MockNetworkAccessManager : public NetworkAccessManager { MockNetworkAccessManager() { ON_CALL(*this, createRequest).WillByDefault(Return(new MockLocalSocketReply{""})); } MOCK_METHOD(QNetworkReply*, createRequest, (Operation, const QNetworkRequest&, QIODevice*), (override)); }; } // namespace test } // namespace multipass #endif // MULTIPASS_MOCK_NETWORK_ACCESS_MANAGER_H
1,310
C++
.h
37
33.135135
108
0.76996
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,061
mock_libc_functions.h
canonical_multipass/tests/unix/mock_libc_functions.h
/* * 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_LIBC_FUNCTIONS_H #define MULTIPASS_MOCK_LIBC_FUNCTIONS_H #include <premock.hpp> #include <grp.h> #include <stdio.h> #include <termios.h> DECL_MOCK(getgrnam); // The following mocks can't use premock directly because they are declared noexcept and the way // premock works is that it uses decltype() to get the function types and then uses this when declaring // the std::function. However, in C++17, std::function can no longer be declared with a noexcept type, so // to avoid that, we basically do what the premock macros do here but be explicit about the types and // not use noexcept. extern "C" std::function<int(int)> mock_isatty; extern "C" std::function<int(FILE*)> mock_fileno; extern "C" std::function<int(int, struct termios*)> mock_tcgetattr; extern "C" std::function<int(int, int, const struct termios*)> mock_tcsetattr; #endif // MULTIPASS_MOCK_LIBC_FUNCTIONS_H
1,532
C++
.h
33
44.818182
106
0.761044
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,062
biomem.h
canonical_multipass/src/cert/biomem.h
/* * 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_BIOMEM_H #define MULTIPASS_BIOMEM_H #include <openssl/bio.h> #include <memory> #include <string> namespace multipass { class BIOMem { public: BIOMem(); BIOMem(const std::string& pem_source); std::string as_string() const; BIO* get() const; private: const std::unique_ptr<BIO, decltype(BIO_free)*> bio; }; } // namespace multipass #endif // MULTIPASS_BIOMEM_H
1,030
C++
.h
35
27.285714
72
0.743434
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,063
ssh_client_key_provider.h
canonical_multipass/src/ssh/ssh_client_key_provider.h
/* * 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_SSH_CLIENT_KEY_PROVIDER_H #define MULTIPASS_SSH_CLIENT_KEY_PROVIDER_H #include <multipass/ssh/ssh_key_provider.h> #include <memory> namespace multipass { class SSHClientKeyProvider : public SSHKeyProvider { public: struct KeyDeleter { void operator()(ssh_key key); }; using KeyUPtr = std::unique_ptr<ssh_key_struct, KeyDeleter>; explicit SSHClientKeyProvider(const std::string& priv_key_blob); std::string private_key_as_base64() const override; std::string public_key_as_base64() const override; ssh_key private_key() const override; private: KeyUPtr priv_key; }; } #endif // MULTIPASS_SSH_CLIENT_KEY_PROVIDER_H
1,310
C++
.h
39
30.897436
72
0.750791
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,064
sshfs_mount.h
canonical_multipass/src/sshfs_mount/sshfs_mount.h
/* * 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_SSHFS_MOUNT #define MULTIPASS_SSHFS_MOUNT #include <multipass/id_mappings.h> #include <memory> #include <thread> #include <unordered_map> namespace multipass { class SSHSession; class SftpServer; class SshfsMount { public: SshfsMount(SSHSession&& session, const std::string& source, const std::string& target, const id_mappings& gid_mappings, const id_mappings& uid_mappings); SshfsMount(SshfsMount&& other); ~SshfsMount(); void stop(); private: // sftp_server Doesn't need to be a pointer, but done for now to avoid bringing sftp.h // which has an error with -pedantic. std::unique_ptr<SftpServer> sftp_server; std::thread sftp_thread; }; } // namespace multipass #endif // MULTIPASS_SSHFS_MOUNT
1,396
C++
.h
42
30.619048
90
0.746291
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,065
sftp_server.h
canonical_multipass/src/sshfs_mount/sftp_server.h
/* * 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_SFTP_SERVER_H #define MULTIPASS_SFTP_SERVER_H #include <multipass/file_ops.h> #include <multipass/id_mappings.h> #include <multipass/recursive_dir_iterator.h> #include <multipass/ssh/ssh_session.h> #include <libssh/sftp.h> #include <memory> #include <unordered_map> #include <QFile> #include <QFileInfo> namespace multipass { class SSHSession; class SSHProcess; class SftpServer { public: SftpServer(SSHSession&& ssh_session, const std::string& source, const std::string& target, const id_mappings& gid_mappings, const id_mappings& uid_mappings, int default_uid, int default_gid, const std::string& sshfs_exec_line); SftpServer(SftpServer&& other); ~SftpServer(); void run(); void stop(); using SSHSessionUptr = std::unique_ptr<ssh_session_struct, decltype(ssh_free)*>; using SftpSessionUptr = std::unique_ptr<sftp_session_struct, decltype(sftp_free)*>; using SSHFSProcUptr = std::unique_ptr<SSHProcess>; private: void process_message(sftp_client_message msg); sftp_attributes_struct attr_from(const QFileInfo& file_info); int mapped_uid_for(const int uid); int mapped_gid_for(const int gid); int reverse_uid_for(const int uid, const int default_id); int reverse_gid_for(const int gid, const int default_id); bool has_uid_mapping_for(const int uid); bool has_gid_mapping_for(const int gid); bool has_reverse_uid_mapping_for(const int uid); bool has_reverse_gid_mapping_for(const int gid); bool has_id_mappings_for(const QFileInfo& file_info); int handle_close(sftp_client_message msg); int handle_fstat(sftp_client_message msg); int handle_mkdir(sftp_client_message msg); int handle_rmdir(sftp_client_message msg); int handle_open(sftp_client_message msg); int handle_opendir(sftp_client_message msg); int handle_read(sftp_client_message msg); int handle_readdir(sftp_client_message msg); int handle_readlink(sftp_client_message msg); int handle_realpath(sftp_client_message msg); int handle_remove(sftp_client_message msg); int handle_rename(sftp_client_message msg); int handle_setstat(sftp_client_message msg); int handle_stat(sftp_client_message msg, bool follow); int handle_symlink(sftp_client_message msg); int handle_write(sftp_client_message msg); int handle_extended(sftp_client_message msg); template <typename T> T* get_handle(sftp_client_message msg); SSHSession ssh_session; SSHFSProcUptr sshfs_process; SftpSessionUptr sftp_server_session; const std::string source_path; const std::string target_path; std::unordered_map<void*, std::unique_ptr<NamedFd>> open_file_handles; std::unordered_map<void*, std::unique_ptr<DirIterator>> open_dir_handles; const id_mappings gid_mappings; const id_mappings uid_mappings; const int default_uid; const int default_gid; const std::string sshfs_exec_line; bool stop_invoked{false}; }; } // namespace multipass #endif // MULTIPASS_SFTP_SERVER_H
3,688
C++
.h
91
36.648352
114
0.738839
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,066
wrapped_qsettings.h
canonical_multipass/src/settings/wrapped_qsettings.h
/* * 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_WRAPPED_QSETTINGS_H #define MULTIPASS_WRAPPED_QSETTINGS_H #include <multipass/disabled_copy_move.h> #include <multipass/singleton.h> #include <QSettings> #include <cassert> namespace multipass { class WrappedQSettingsFactory; class WrappedQSettings : private DisabledCopyMove { public: virtual ~WrappedQSettings() = default; virtual QSettings::Status status() const { assert(qsettings); return qsettings->status(); } virtual QString fileName() const { assert(qsettings); return qsettings->fileName(); } virtual void sync() { assert(qsettings); qsettings->sync(); } virtual void setValue(const QString& key, const QVariant& value) { assert(qsettings); qsettings->setValue(key, value); } virtual void remove(const QString& key) { assert(qsettings); qsettings->remove(key); } QVariant value(const QString& key, const QVariant& default_value = QVariant()) const { return value_impl(key, default_value); // indirection avoids default args in virtual method } protected: WrappedQSettings() = default; // for mocks virtual QVariant value_impl(const QString& key, const QVariant& default_value) const { assert(qsettings); return qsettings->value(key, default_value); } private: friend class WrappedQSettingsFactory; explicit WrappedQSettings(std::unique_ptr<QSettings>&& qsettings) noexcept : qsettings{std::move(qsettings)} { } std::unique_ptr<QSettings> qsettings; }; class WrappedQSettingsFactory : public Singleton<WrappedQSettingsFactory> { public: explicit WrappedQSettingsFactory(const Singleton::PrivatePass& pass) : Singleton{pass} { } virtual std::unique_ptr<WrappedQSettings> make_wrapped_qsettings(const QString& file_path, QSettings::Format format) const { auto qsettings = std::make_unique<QSettings>(file_path, format); return std::unique_ptr<WrappedQSettings>(new WrappedQSettings(std::move(qsettings))); /* std::make_unique can't call private ctors, so we call it ourselves; but the ctor is noexcept, so no leaks */ } }; } // namespace multipass #endif // MULTIPASS_WRAPPED_QSETTINGS_H
3,019
C++
.h
88
28.840909
120
0.694816
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,067
platform_shared.h
canonical_multipass/src/platform/platform_shared.h
/* * 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_PLATFORM_SHARED_H #define MULTIPASS_PLATFORM_SHARED_H #include <string> #include <unordered_set> namespace multipass::platform { const std::unordered_set<std::string> supported_snapcraft_aliases{ "core18", "18.04", "core20", "20.04", "core22", "22.04", "core24", "24.04", "devel", }; } // namespace multipass::platform #endif // MULTIPASS_PLATFORM_SHARED_H
1,082
C++
.h
35
27.228571
73
0.705486
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,068
platform_linux_detail.h
canonical_multipass/src/platform/platform_linux_detail.h
/* * 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_PLATFORM_LINUX_DETAIL_H #define MULTIPASS_PLATFORM_LINUX_DETAIL_H #include <multipass/network_interface_info.h> #include <map> namespace multipass::platform::detail { std::map<std::string, NetworkInterfaceInfo> get_network_interfaces_from(const QDir& sys_dir); std::unique_ptr<QFile> find_os_release(); std::pair<QString, QString> parse_os_release(const QStringList& os_data); std::string read_os_release(); } // namespace multipass::platform::detail #endif // MULTIPASS_PLATFORM_LINUX_DETAIL_H
1,146
C++
.h
28
39.214286
93
0.771788
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,069
unix_terminal.h
canonical_multipass/src/platform/console/unix_terminal.h
/* * 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_UNIX_TERMINAL_H #define MULTIPASS_UNIX_TERMINAL_H #include <multipass/terminal.h> namespace multipass { class UnixTerminal : public Terminal { public: int cin_fd() const; bool cin_is_live() const override; int cout_fd() const; bool cout_is_live() const override; void set_cin_echo(const bool enable) override; }; } // namespace multipass #endif // MULTIPASS_UNIX_TERMINAL_H
1,046
C++
.h
32
30.40625
72
0.752976
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,070
unix_console.h
canonical_multipass/src/platform/console/unix_console.h
/* * 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_UNIX_CONSOLE_H #define MULTIPASS_UNIX_CONSOLE_H #include <multipass/console.h> #include <libssh/libssh.h> #include <vector> #include <csignal> #include <termios.h> #include "unix_terminal.h" namespace multipass { class UnixConsole final : public Console { public: explicit UnixConsole(ssh_channel channel, UnixTerminal *term); ~UnixConsole(); void read_console() override{}; void write_console() override{}; void exit_console() override{}; static void setup_environment(); private: void setup_console(); void restore_console(); UnixTerminal* term; struct termios saved_terminal; struct sigaction winch_action; }; } // namespace multipass #endif // MULTIPASS_UNIX_CONSOLE_H
1,373
C++
.h
44
28.636364
72
0.751327
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,071
libvirt_virtual_machine.h
canonical_multipass/src/platform/backends/libvirt/libvirt_virtual_machine.h
/* * 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_LIBVIRT_VIRTUAL_MACHINE_H #define MULTIPASS_LIBVIRT_VIRTUAL_MACHINE_H #include "libvirt_wrapper.h" #include <shared/base_virtual_machine.h> #include <multipass/virtual_machine_description.h> namespace multipass { class VMStatusMonitor; class LibVirtVirtualMachine final : public BaseVirtualMachine { public: using ConnectionUPtr = std::unique_ptr<virConnect, decltype(virConnectClose)*>; using DomainUPtr = std::unique_ptr<virDomain, decltype(virDomainFree)*>; using NetworkUPtr = std::unique_ptr<virNetwork, decltype(virNetworkFree)*>; LibVirtVirtualMachine(const VirtualMachineDescription& desc, const std::string& bridge_name, VMStatusMonitor& monitor, const LibvirtWrapper::UPtr& libvirt_wrapper, const SSHKeyProvider& key_provider, const Path& instance_dir); ~LibVirtVirtualMachine(); void start() override; void shutdown(ShutdownPolicy shutdown_policy = ShutdownPolicy::Powerdown) override; void suspend() override; State current_state() override; int ssh_port() override; std::string ssh_hostname(std::chrono::milliseconds timeout) override; std::string ssh_username() override; std::string management_ipv4() override; std::string ipv6() override; void ensure_vm_is_running() override; void update_state() override; void update_cpus(int num_cores) override; void resize_memory(const MemorySize& new_size) override; void resize_disk(const MemorySize& new_size) override; static ConnectionUPtr open_libvirt_connection(const LibvirtWrapper::UPtr& libvirt_wrapper); private: DomainUPtr initialize_domain_info(virConnectPtr connection); DomainUPtr checked_vm_domain() const; std::string mac_addr; const std::string username; VirtualMachineDescription desc; VMStatusMonitor* monitor; // Make this a reference since LibVirtVirtualMachineFactory can modify the name later const std::string& bridge_name; // Needs to be a reference so testing can override the various libvirt functions const LibvirtWrapper::UPtr& libvirt_wrapper; bool update_suspend_status{true}; }; } // namespace multipass #endif // MULTIPASS_LIBVIRT_VIRTUAL_MACHINE_H
2,949
C++
.h
67
38.820896
95
0.737631
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,072
libvirt_virtual_machine_factory.h
canonical_multipass/src/platform/backends/libvirt/libvirt_virtual_machine_factory.h
/* * 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_LIBVIRT_VIRTUAL_MACHINE_FACTORY_H #define MULTIPASS_LIBVIRT_VIRTUAL_MACHINE_FACTORY_H #include "libvirt_wrapper.h" #include <shared/base_virtual_machine_factory.h> #include <memory> #include <string> namespace multipass { class ProcessFactory; class LibVirtVirtualMachineFactory final : public BaseVirtualMachineFactory { public: explicit LibVirtVirtualMachineFactory(const Path& data_dir, const std::string& libvirt_object_path); // For testing explicit LibVirtVirtualMachineFactory(const Path& data_dir); ~LibVirtVirtualMachineFactory(); VirtualMachine::UPtr create_virtual_machine(const VirtualMachineDescription& desc, const SSHKeyProvider& key_provider, VMStatusMonitor& monitor) override; VMImage prepare_source_image(const VMImage& source_image) override; void prepare_instance_image(const VMImage& instance_image, const VirtualMachineDescription& desc) override; void hypervisor_health_check() override; QString get_backend_version_string() const override; // Making this public makes this modifiable which is necessary for testing LibvirtWrapper::UPtr libvirt_wrapper; protected: void remove_resources_for_impl(const std::string& name) override; private: const Path data_dir; std::string bridge_name; const std::string libvirt_object_path; }; } // namespace multipass #endif // MULTIPASS_LIBVIRT_VIRTUAL_MACHINE_FACTORY_H
2,139
C++
.h
49
39.040816
119
0.751923
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,073
libvirt_wrapper.h
canonical_multipass/src/platform/backends/libvirt/libvirt_wrapper.h
/* * 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_LIBVIRT_WRAPPER_H #define MULTIPASS_LIBVIRT_WRAPPER_H #include <stdexcept> #include <string> #include <multipass/format.h> #include <libvirt/libvirt.h> #include <libvirt/virterror.h> namespace multipass { class BaseLibvirtException : public std::runtime_error { public: BaseLibvirtException(const std::string& error_message) : runtime_error(error_message) { } }; class LibvirtOpenException : public BaseLibvirtException { public: LibvirtOpenException(const char* error_message) : BaseLibvirtException(fmt::format("Failed to open the libvirt object: {}", error_message)) { } }; class LibvirtSymbolAddressException : public BaseLibvirtException { public: LibvirtSymbolAddressException(const std::string& symbol, const char* error_message) : BaseLibvirtException(fmt::format("Failed to load symbol \"{}\": {}", symbol, error_message)) { } }; class LibvirtWrapper { private: typedef virConnectPtr (*virConnectOpen_t)(const char* name); typedef int (*virConnectClose_t)(virConnectPtr conn); typedef char* (*virConnectGetCapabilities_t)(virConnectPtr conn); typedef int (*virConnectGetVersion_t)(virConnectPtr conn, unsigned long* hvVer); typedef virNetworkPtr (*virNetworkLookupByName_t)(virConnectPtr conn, const char* name); typedef virNetworkPtr (*virNetworkCreateXML_t)(virConnectPtr conn, const char* xmlDesc); typedef int (*virNetworkDestroy_t)(virNetworkPtr network); typedef int (*virNetworkFree_t)(virNetworkPtr network); typedef char* (*virNetworkGetBridgeName_t)(virNetworkPtr network); typedef int (*virNetworkIsActive_t)(virNetworkPtr network); typedef int (*virNetworkCreate_t)(virNetworkPtr network); typedef int (*virNetworkGetDHCPLeases_t)(virNetworkPtr network, const char* mac, virNetworkDHCPLeasePtr** leases, unsigned int flags); typedef void (*virNetworkDHCPLeaseFree_t)(virNetworkDHCPLeasePtr lease); typedef int (*virDomainUndefine_t)(virDomainPtr domain); typedef virDomainPtr (*virDomainLookupByName_t)(virConnectPtr conn, const char* name); typedef char* (*virDomainGetXMLDesc_t)(virDomainPtr domain, unsigned int flags); typedef int (*virDomainDestroy_t)(virDomainPtr domain); typedef int (*virDomainFree_t)(virDomainPtr domain); typedef virDomainPtr (*virDomainDefineXML_t)(virConnectPtr conn, const char* xml); typedef int (*virDomainGetState_t)(virDomainPtr domain, int* state, int* reason, unsigned int flags); typedef int (*virDomainCreate_t)(virDomainPtr domain); typedef int (*virDomainShutdown_t)(virDomainPtr domain); typedef int (*virDomainManagedSave_t)(virDomainPtr domain, unsigned int flags); typedef int (*virDomainHasManagedSaveImage_t)(virDomainPtr domain, unsigned int flags); typedef int (*virDomainSetVcpusFlags_t)(virDomainPtr domain, unsigned int nvcpus, unsigned int flags); typedef int (*virDomainSetMemoryFlags_t)(virDomainPtr domain, unsigned long memory, unsigned int flags); typedef const char* (*virGetLastErrorMessage_t)(); void* handle{nullptr}; public: using UPtr = std::unique_ptr<LibvirtWrapper>; LibvirtWrapper(const std::string& filename = "libvirt.so.0"); ~LibvirtWrapper(); virConnectOpen_t virConnectOpen; virConnectClose_t virConnectClose; virConnectGetCapabilities_t virConnectGetCapabilities; virConnectGetVersion_t virConnectGetVersion; virNetworkLookupByName_t virNetworkLookupByName; virNetworkCreateXML_t virNetworkCreateXML; virNetworkDestroy_t virNetworkDestroy; virNetworkFree_t virNetworkFree; virNetworkGetBridgeName_t virNetworkGetBridgeName; virNetworkIsActive_t virNetworkIsActive; virNetworkCreate_t virNetworkCreate; virNetworkGetDHCPLeases_t virNetworkGetDHCPLeases; virNetworkDHCPLeaseFree_t virNetworkDHCPLeaseFree; virDomainUndefine_t virDomainUndefine; virDomainLookupByName_t virDomainLookupByName; virDomainGetXMLDesc_t virDomainGetXMLDesc; virDomainDestroy_t virDomainDestroy; virDomainFree_t virDomainFree; virDomainDefineXML_t virDomainDefineXML; virDomainGetState_t virDomainGetState; virDomainCreate_t virDomainCreate; virDomainShutdown_t virDomainShutdown; virDomainManagedSave_t virDomainManagedSave; virDomainHasManagedSaveImage_t virDomainHasManagedSaveImage; virDomainSetVcpusFlags_t virDomainSetVcpusFlags; virDomainSetMemoryFlags_t virDomainSetMemoryFlags; virGetLastErrorMessage_t virGetLastErrorMessage; }; } // namespace multipass #endif // MULTIPASS_LIBVIRT_WRAPPER_H
5,258
C++
.h
114
41.991228
117
0.78016
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,074
shared_backend_utils.h
canonical_multipass/src/platform/backends/shared/shared_backend_utils.h
/* * 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_SHARED_BACKEND_UTILS_H #define MULTIPASS_SHARED_BACKEND_UTILS_H #include <multipass/exceptions/internal_timeout_exception.h> #include <multipass/exceptions/start_exception.h> #include <multipass/utils.h> #include <multipass/virtual_machine.h> #include <chrono> #include <string> namespace multipass { namespace backend { using namespace std::chrono_literals; template <typename Callable> std::string ip_address_for(VirtualMachine* virtual_machine, Callable&& get_ip, std::chrono::milliseconds timeout) { if (!virtual_machine->management_ip) { auto action = [virtual_machine, get_ip] { virtual_machine->ensure_vm_is_running(); auto result = get_ip(); if (result) { virtual_machine->management_ip.emplace(*result); return utils::TimeoutAction::done; } else { return utils::TimeoutAction::retry; } }; auto on_timeout = [virtual_machine, &timeout] { virtual_machine->state = VirtualMachine::State::unknown; throw InternalTimeoutException{"determine IP address", timeout}; }; utils::try_action_for(on_timeout, timeout, action); } return virtual_machine->management_ip->as_string(); } template <typename Callable> void ensure_vm_is_running_for(VirtualMachine* virtual_machine, Callable&& is_vm_running, const std::string& msg) { std::lock_guard<decltype(virtual_machine->state_mutex)> lock{virtual_machine->state_mutex}; if (!is_vm_running()) { virtual_machine->shutdown_while_starting = true; virtual_machine->state_wait.notify_all(); throw StartException(virtual_machine->vm_name, msg); } } } // namespace backend } // namespace multipass #endif // MULTIPASS_SHARED_BACKEND_UTILS_H
2,498
C++
.h
69
31.014493
113
0.694088
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,075
base_vm_image_vault.h
canonical_multipass/src/platform/backends/shared/base_vm_image_vault.h
/* * 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_BASE_VM_IMAGE_VAULT_H #define MULTIPASS_BASE_VM_IMAGE_VAULT_H #include <multipass/format.h> #include <multipass/query.h> #include <multipass/vm_image.h> #include <multipass/vm_image_host.h> #include <multipass/vm_image_vault.h> #include <string> #include <utility> #include <vector> namespace multipass { class BaseVMImageVault : public VMImageVault { public: explicit BaseVMImageVault(const std::vector<VMImageHost*>& image_hosts) : image_hosts{image_hosts}, remote_image_host_map{vault::configure_image_host_map(image_hosts)} {}; VMImageHost* image_host_for(const std::string& remote_name) const override { auto it = remote_image_host_map.find(remote_name); if (it == remote_image_host_map.end()) { throw std::runtime_error( fmt::format("Remote \'{}\' is not found. Please use `multipass find` for supported remotes and images.", remote_name)); } return it->second; }; std::vector<std::pair<std::string, VMImageInfo>> all_info_for(const Query& query) const override { std::vector<std::pair<std::string, VMImageInfo>> images_info; auto grab_imgs = [&images_info, &query](auto* image_host) { return !(images_info = image_host->all_info_for(query)).empty(); }; if (!query.remote_name.empty()) images_info = image_host_for(query.remote_name)->all_info_for(query); else static_cast<void>(std::any_of(image_hosts.begin(), image_hosts.end(), grab_imgs)); // intentional discard return images_info; }; protected: virtual std::optional<VMImageInfo> info_for(const Query& query) const { std::optional<VMImageInfo> info; if (!query.remote_name.empty()) { auto image_host = image_host_for(query.remote_name); info = image_host->info_for(query); } else { for (const auto& image_host : image_hosts) { info = image_host->info_for(query); if (info) break; } } return info; }; private: std::vector<VMImageHost*> image_hosts; std::unordered_map<std::string, VMImageHost*> remote_image_host_map; }; } // namespace multipass #endif // MULTIPASS_BASE_VM_IMAGE_VAULT_H
3,023
C++
.h
82
30.463415
120
0.650256
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,076
base_virtual_machine.h
canonical_multipass/src/platform/backends/shared/base_virtual_machine.h
/* * 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_BASE_VIRTUAL_MACHINE_H #define MULTIPASS_BASE_VIRTUAL_MACHINE_H #include <multipass/exceptions/not_implemented_on_this_backend_exception.h> #include <multipass/logging/log.h> #include <multipass/path.h> #include <multipass/utils.h> #include <multipass/virtual_machine.h> #include <fmt/format.h> #include <QRegularExpression> #include <QString> #include <memory> #include <mutex> #include <optional> #include <unordered_map> namespace multipass { class SSHSession; class SSHKeyProvider; class BaseVirtualMachine : public VirtualMachine { public: BaseVirtualMachine(VirtualMachine::State state, const std::string& vm_name, const SSHKeyProvider& key_provider, const Path& instance_dir); BaseVirtualMachine(const std::string& vm_name, const SSHKeyProvider& key_provider, const Path& instance_dir); virtual std::string ssh_exec(const std::string& cmd, bool whisper = false) override; void wait_until_ssh_up(std::chrono::milliseconds timeout) override; void wait_for_cloud_init(std::chrono::milliseconds timeout) override; std::vector<std::string> get_all_ipv4() override; void add_network_interface(int index, const std::string& default_mac_addr, const NetworkInterface& extra_interface) override { throw NotImplementedOnThisBackendException("networks"); } std::unique_ptr<MountHandler> make_native_mount_handler(const std::string& target, const VMMount& mount) override { throw NotImplementedOnThisBackendException("native mounts"); } SnapshotVista view_snapshots() const override; int get_num_snapshots() const override; std::shared_ptr<const Snapshot> get_snapshot(const std::string& name) const override; std::shared_ptr<const Snapshot> get_snapshot(int index) const override; std::shared_ptr<Snapshot> get_snapshot(const std::string& name) override; std::shared_ptr<Snapshot> get_snapshot(int index) override; // TODO: the VM should know its directory, but that is true of everything in its VMDescription; pulling that from // derived classes is a big refactor std::shared_ptr<const Snapshot> take_snapshot(const VMSpecs& specs, const std::string& snapshot_name, const std::string& comment) override; void rename_snapshot(const std::string& old_name, const std::string& new_name) override; void delete_snapshot(const std::string& name) override; void restore_snapshot(const std::string& name, VMSpecs& specs) override; void load_snapshots() override; std::vector<std::string> get_childrens_names(const Snapshot* parent) const override; int get_snapshot_count() const override; void remove_snapshots_from_image() const override { throw NotImplementedOnThisBackendException("snapshots"); } protected: virtual void require_snapshots_support() const; virtual std::shared_ptr<Snapshot> make_specific_snapshot(const QString& filename); virtual std::shared_ptr<Snapshot> make_specific_snapshot(const std::string& snapshot_name, const std::string& comment, const std::string& instance_id, const VMSpecs& specs, std::shared_ptr<Snapshot> parent); virtual void drop_ssh_session(); // virtual to allow mocking void renew_ssh_session(); virtual void add_extra_interface_to_instance_cloud_init(const std::string& default_mac_addr, const NetworkInterface& extra_interface) const; virtual void apply_extra_interfaces_and_instance_id_to_cloud_init( const std::string& default_mac_addr, const std::vector<NetworkInterface>& extra_interfaces, const std::string& new_instance_id) const; virtual std::string get_instance_id_from_the_cloud_init() const; virtual void check_state_for_shutdown(ShutdownPolicy shutdown_policy); private: using SnapshotMap = std::unordered_map<std::string, std::shared_ptr<Snapshot>>; template <typename LockT> void log_latest_snapshot(LockT lock) const; void load_generic_snapshot_info(); void load_snapshot(const QString& filename); auto make_take_snapshot_rollback(SnapshotMap::iterator it); void take_snapshot_rollback_helper(SnapshotMap::iterator it, std::shared_ptr<Snapshot>& old_head, int old_count); auto make_common_file_rollback(const Path& file_path, QFile& file, const std::string& old_contents) const; void common_file_rollback_helper(const Path& file_path, QFile& file, const std::string& old_contents, bool existed) const; void persist_generic_snapshot_info() const; void persist_head_snapshot_index(const Path& head_path) const; std::string generate_snapshot_name() const; template <typename NodeT> auto make_reinsert_guard(NodeT& snapshot_node); auto make_restore_rollback(const Path& head_path, VMSpecs& specs); void restore_rollback_helper(const Path& head_path, const std::shared_ptr<Snapshot>& old_head, const VMSpecs& old_specs, VMSpecs& specs); bool updated_deleted_head(std::shared_ptr<Snapshot>& snapshot, const Path& head_path); auto make_deleted_head_rollback(const Path& head_path, const bool& wrote_head); void deleted_head_rollback_helper(const Path& head_path, const bool& wrote_head, std::shared_ptr<Snapshot>& old_head); void update_parents(std::shared_ptr<Snapshot>& deleted_parent, std::vector<Snapshot*>& updated_parents); auto make_parent_update_rollback(const std::shared_ptr<Snapshot>& deleted_parent, std::vector<Snapshot*>& updated_snapshot_paths) const; void delete_snapshot_helper(std::shared_ptr<Snapshot>& snapshot); protected: const SSHKeyProvider& key_provider; private: std::optional<SSHSession> ssh_session = std::nullopt; SnapshotMap snapshots; std::shared_ptr<Snapshot> head_snapshot = nullptr; int snapshot_count = 0; // tracks the number of snapshots ever taken (regardless of deletes) mutable std::recursive_mutex snapshot_mutex; }; } // namespace multipass inline int multipass::BaseVirtualMachine::get_num_snapshots() const { require_snapshots_support(); return static_cast<int>(snapshots.size()); } inline int multipass::BaseVirtualMachine::get_snapshot_count() const { require_snapshots_support(); const std::unique_lock lock{snapshot_mutex}; return snapshot_count; } inline void multipass::BaseVirtualMachine::require_snapshots_support() const { throw NotImplementedOnThisBackendException{"snapshots"}; } #endif // MULTIPASS_BASE_VIRTUAL_MACHINE_H
7,894
C++
.h
153
42.444444
117
0.676139
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,077
sshfs_server_process_spec.h
canonical_multipass/src/platform/backends/shared/sshfs_server_process_spec.h
/* * 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_SSHFS_SERVER_PROCESS_SPEC_H #define MULTIPASS_SSHFS_SERVER_PROCESS_SPEC_H #include <multipass/process/process_spec.h> #include <multipass/sshfs_server_config.h> namespace multipass { class SSHFSServerProcessSpec : public ProcessSpec { public: explicit SSHFSServerProcessSpec(const SSHFSServerConfig& config); QString program() const override; QStringList arguments() const override; QProcessEnvironment environment() const override; logging::Level error_log_level() const override; QString apparmor_profile() const override; QString identifier() const override; private: const SSHFSServerConfig config; const QByteArray target_hash; }; } // namespace multipass #endif // MULTIPASS_SSHFS_SERVER_PROCESS_SPEC_H
1,401
C++
.h
38
34.263158
72
0.778271
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,078
base_snapshot.h
canonical_multipass/src/platform/backends/shared/base_snapshot.h
/* * 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_BASE_SNAPSHOT_H #define MULTIPASS_BASE_SNAPSHOT_H #include <multipass/snapshot.h> #include <multipass/memory_size.h> #include <multipass/vm_mount.h> #include <QJsonObject> #include <QString> #include <mutex> namespace multipass { struct VMSpecs; class VirtualMachineDescription; class BaseSnapshot : public Snapshot { public: BaseSnapshot(const std::string& name, const std::string& comment, const std::string& cloud_init_instance_id, std::shared_ptr<Snapshot> parent, const VMSpecs& specs, const VirtualMachine& vm); BaseSnapshot(const QString& filename, VirtualMachine& vm, const VirtualMachineDescription& desc); int get_index() const noexcept override; std::string get_name() const override; std::string get_comment() const override; std::string get_cloud_init_instance_id() const noexcept override; QDateTime get_creation_timestamp() const noexcept override; int get_num_cores() const noexcept override; MemorySize get_mem_size() const noexcept override; MemorySize get_disk_space() const noexcept override; std::vector<NetworkInterface> get_extra_interfaces() const noexcept override; VirtualMachine::State get_state() const noexcept override; // Note that these return references - careful not to delete the snapshot while they are in use const std::unordered_map<std::string, VMMount>& get_mounts() const noexcept override; const QJsonObject& get_metadata() const noexcept override; std::shared_ptr<const Snapshot> get_parent() const override; std::shared_ptr<Snapshot> get_parent() override; std::string get_parents_name() const override; int get_parents_index() const override; void set_name(const std::string& n) override; void set_comment(const std::string& c) override; void set_parent(std::shared_ptr<Snapshot> p) override; void capture() final; void erase() final; void apply() final; protected: const QString& get_id() const noexcept; virtual void capture_impl() = 0; virtual void erase_impl() = 0; virtual void apply_impl() = 0; private: BaseSnapshot(const QJsonObject& json, VirtualMachine& vm, const VirtualMachineDescription& desc); BaseSnapshot(const std::string& name, const std::string& comment, const std::string& cloud_init_instance_id, std::shared_ptr<Snapshot> parent, int index, QDateTime&& creation_timestamp, int num_cores, MemorySize mem_size, MemorySize disk_space, std::vector<NetworkInterface> extra_interfaces, VirtualMachine::State state, std::unordered_map<std::string, VMMount> mounts, QJsonObject metadata, const QDir& storage_dir, bool captured); auto erase_helper(); QString derive_snapshot_filename() const; QJsonObject serialize() const; void persist() const; private: std::string name; std::string comment; std::shared_ptr<Snapshot> parent; // This class is non-copyable and having these const simplifies thread safety const std::string cloud_init_instance_id; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const int index; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const QString id; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const QDateTime creation_timestamp; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const int num_cores; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const MemorySize mem_size; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const MemorySize disk_space; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const std::vector<NetworkInterface> extra_interfaces; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const VirtualMachine::State state; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const std::unordered_map<std::string, VMMount> mounts; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const QJsonObject metadata; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) const QDir storage_dir; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) bool captured; mutable std::recursive_mutex mutex; }; } // namespace multipass inline std::string multipass::BaseSnapshot::get_name() const { const std::unique_lock lock{mutex}; return name; } inline std::string multipass::BaseSnapshot::get_comment() const { const std::unique_lock lock{mutex}; return comment; } inline std::string multipass::BaseSnapshot::get_cloud_init_instance_id() const noexcept { return cloud_init_instance_id; } inline int multipass::BaseSnapshot::get_index() const noexcept { return index; } inline QDateTime multipass::BaseSnapshot::get_creation_timestamp() const noexcept { return creation_timestamp; } inline std::string multipass::BaseSnapshot::get_parents_name() const { std::unique_lock lock{mutex}; auto par = parent; lock.unlock(); // avoid locking another snapshot while locked in here return par ? par->get_name() : ""; } inline int multipass::BaseSnapshot::get_parents_index() const { const std::unique_lock lock{mutex}; return parent ? parent->get_index() : 0; // this doesn't lock } inline auto multipass::BaseSnapshot::get_parent() const -> std::shared_ptr<const Snapshot> { const std::unique_lock lock{mutex}; return parent; } inline auto multipass::BaseSnapshot::get_parent() -> std::shared_ptr<Snapshot> { return std::const_pointer_cast<Snapshot>(std::as_const(*this).get_parent()); } inline int multipass::BaseSnapshot::get_num_cores() const noexcept { return num_cores; } inline auto multipass::BaseSnapshot::get_mem_size() const noexcept -> MemorySize { return mem_size; } inline auto multipass::BaseSnapshot::get_disk_space() const noexcept -> MemorySize { return disk_space; } inline auto multipass::BaseSnapshot::get_extra_interfaces() const noexcept -> std::vector<NetworkInterface> { return extra_interfaces; } inline auto multipass::BaseSnapshot::get_state() const noexcept -> VirtualMachine::State { return state; } inline auto multipass::BaseSnapshot::get_mounts() const noexcept -> const std::unordered_map<std::string, VMMount>& { return mounts; } inline const QJsonObject& multipass::BaseSnapshot::get_metadata() const noexcept { return metadata; } inline void multipass::BaseSnapshot::set_name(const std::string& n) { const std::unique_lock lock{mutex}; assert(captured && "precondition: only captured snapshots can be edited"); name = n; persist(); } inline void multipass::BaseSnapshot::set_comment(const std::string& c) { const std::unique_lock lock{mutex}; assert(captured && "precondition: only captured snapshots can be edited"); comment = c; persist(); } inline void multipass::BaseSnapshot::set_parent(std::shared_ptr<Snapshot> p) { const std::unique_lock lock{mutex}; assert(captured && "precondition: only captured snapshots can be edited"); parent = std::move(p); persist(); } inline void multipass::BaseSnapshot::capture() { const std::unique_lock lock{mutex}; assert(!captured && "pre-condition: capture should only be called once, and only for snapshots that were not loaded from disk"); if (!captured) { captured = true; capture_impl(); persist(); } } inline void multipass::BaseSnapshot::apply() { const std::unique_lock lock{mutex}; apply_impl(); // no need to persist here for the time being: only private fields of the base class are persisted for now, and // those cannot be affected by apply_impl (except by setters, which already persist) } inline const QString& multipass::BaseSnapshot::get_id() const noexcept { return id; } #endif // MULTIPASS_BASE_SNAPSHOT_H
9,041
C++
.h
224
35.732143
119
0.697913
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,079
base_virtual_machine_factory.h
canonical_multipass/src/platform/backends/shared/base_virtual_machine_factory.h
/* * 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_BASE_VIRTUAL_MACHINE_FACTORY_H #define MULTIPASS_BASE_VIRTUAL_MACHINE_FACTORY_H #include <multipass/exceptions/not_implemented_on_this_backend_exception.h> #include <multipass/format.h> #include <multipass/logging/log.h> #include <multipass/mount_handler.h> #include <multipass/utils.h> #include <multipass/virtual_machine_factory.h> #include <daemon/default_vm_image_vault.h> namespace multipass { constexpr auto log_category = "base factory"; class BaseVirtualMachineFactory : public VirtualMachineFactory { public: explicit BaseVirtualMachineFactory(const Path& instances_dir); VirtualMachine::UPtr create_vm_and_clone_instance_dir_data(const VMSpecs& src_vm_spec, const VMSpecs& dest_vm_spec, const std::string& source_name, const std::string& destination_name, const VMImage& dest_vm_image, const SSHKeyProvider& key_provider, VMStatusMonitor& monitor) override { throw NotImplementedOnThisBackendException("clone"); } void remove_resources_for(const std::string& name) final; FetchType fetch_type() override { return FetchType::ImageOnly; }; QString get_backend_directory_name() const override { return {}; }; Path get_instance_directory(const std::string& name) const override { return utils::backend_directory_path(instances_dir, QString::fromStdString(name)); } void prepare_networking(std::vector<NetworkInterface>& extra_interfaces) override; VMImageVault::UPtr create_image_vault(std::vector<VMImageHost*> image_hosts, URLDownloader* downloader, const Path& cache_dir_path, const Path& data_dir_path, const days& days_to_expire) override { return std::make_unique<DefaultVMImageVault>(image_hosts, downloader, cache_dir_path, data_dir_path, days_to_expire); }; void configure(VirtualMachineDescription& vm_desc) override; std::vector<NetworkInterfaceInfo> networks() const override { throw NotImplementedOnThisBackendException("networks"); }; void require_snapshots_support() const override; void require_suspend_support() const override; void require_clone_support() const override { throw NotImplementedOnThisBackendException{"clone"}; } protected: static const Path instances_subdir; protected: std::string create_bridge_with(const NetworkInterfaceInfo& interface) override { throw NotImplementedOnThisBackendException{"bridge creation"}; } virtual void prepare_interface(NetworkInterface& net, std::vector<NetworkInterfaceInfo>& host_nets); virtual void remove_resources_for_impl(const std::string& name) = 0; private: Path instances_dir; }; namespace fs = std::filesystem; void copy_instance_dir_with_essential_files(const fs::path& source_instance_dir_path, const fs::path& dest_instance_dir_path); } // namespace multipass inline void multipass::BaseVirtualMachineFactory::remove_resources_for(const std::string& name) { remove_resources_for_impl(name); QDir instance_dir{get_instance_directory(name)}; instance_dir.removeRecursively(); } inline void multipass::BaseVirtualMachineFactory::require_snapshots_support() const { throw NotImplementedOnThisBackendException{"snapshots"}; } inline void multipass::BaseVirtualMachineFactory::require_suspend_support() const { } #endif // MULTIPASS_BASE_VIRTUAL_MACHINE_FACTORY_H
4,587
C++
.h
104
35.259615
108
0.670855
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,080
process_factory.h
canonical_multipass/src/platform/backends/shared/linux/process_factory.h
/* * 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_PROCESS_FACTORY_H #define MULTIPASS_PROCESS_FACTORY_H #include "apparmor.h" #include <multipass/process/process_spec.h> #include <multipass/singleton.h> #include <memory> #include <optional> #define MP_PROCFACTORY multipass::ProcessFactory::instance() namespace multipass { class Process; class ProcessFactory : public Singleton<ProcessFactory> { public: ProcessFactory(const Singleton<ProcessFactory>::PrivatePass&); virtual std::unique_ptr<Process> create_process(std::unique_ptr<ProcessSpec>&& process_spec) const; std::unique_ptr<Process> create_process(const QString& command, const QStringList& args = QStringList()) const; private: const std::optional<AppArmor> apparmor; }; } // namespace multipass #endif // MULTIPASS_PROCESS_FACTORY_H
1,417
C++
.h
38
35.210526
115
0.77721
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
21,081
apparmor.h
canonical_multipass/src/platform/backends/shared/linux/apparmor.h
/* * 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_APPARMOR_H #define MULTIPASS_APPARMOR_H #include <QStringList> namespace multipass { class AppArmor { public: AppArmor(); void load_policy(const QByteArray& aa_policy) const; void remove_policy(const QByteArray& aa_policy) const; void next_exec_under_policy(const QByteArray& aa_policy_name) const; private: const QStringList apparmor_args; }; class AppArmorException : public std::runtime_error { public: AppArmorException(const std::string& msg) : runtime_error{msg} { } }; } // namespace multipass #endif // MULTIPASS_APPARMOR_CONFINEMENT_H
1,232
C++
.h
40
28.375
72
0.759729
canonical/multipass
7,732
642
476
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false