mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
👷 gucc: use doctest instead of raw C asserts
This commit is contained in:
parent
deaf0e8d0a
commit
b3929ef98e
@ -77,6 +77,12 @@ CPMAddPackage(
|
|||||||
GIT_TAG v3.9.0
|
GIT_TAG v3.9.0
|
||||||
EXCLUDE_FROM_ALL YES
|
EXCLUDE_FROM_ALL YES
|
||||||
)
|
)
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME doctest
|
||||||
|
GITHUB_REPOSITORY doctest/doctest
|
||||||
|
GIT_TAG v2.4.11
|
||||||
|
EXCLUDE_FROM_ALL YES
|
||||||
|
)
|
||||||
|
|
||||||
##
|
##
|
||||||
## CONFIGURATION
|
## CONFIGURATION
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
#############################################################################
|
||||||
|
# doctest library with the main function to speed up build
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
add_library(doctest_main OBJECT unit.cpp)
|
||||||
|
target_compile_features(doctest_main PUBLIC cxx_std_23)
|
||||||
|
target_include_directories(doctest_main PRIVATE ${CMAKE_BINARY_DIR}/include ${CMAKE_CURRENT_DIR})
|
||||||
|
target_link_libraries(doctest_main PRIVATE doctest::doctest)
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# one executable for each unit test file
|
# one executable for each unit test file
|
||||||
#############################################################################
|
#############################################################################
|
||||||
@ -11,12 +20,18 @@ foreach(file ${files})
|
|||||||
get_filename_component(file_basename ${file} NAME_WE)
|
get_filename_component(file_basename ${file} NAME_WE)
|
||||||
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
||||||
|
|
||||||
add_executable(${testcase} ${file})
|
add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
|
||||||
|
target_compile_definitions(${testcase} PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
|
||||||
target_compile_options(${testcase} PRIVATE
|
target_compile_options(${testcase} PRIVATE
|
||||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||||
)
|
)
|
||||||
add_definitions(-DGUCC_TEST_DIR="${GUCC_TEST_DIR}")
|
add_definitions(-DGUCC_TEST_DIR="${GUCC_TEST_DIR}")
|
||||||
add_definitions(-DGUCC_TOP_DIR="${GUCC_TOP_DIR}")
|
add_definitions(-DGUCC_TOP_DIR="${GUCC_TOP_DIR}")
|
||||||
target_link_libraries(${testcase} PRIVATE project_warnings project_options gucc::gucc)
|
target_link_libraries(${testcase} PRIVATE project_warnings project_options gucc::gucc doctest::doctest)
|
||||||
|
|
||||||
|
add_test(NAME "${testcase}"
|
||||||
|
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
32
gucc/tests/doctest_compatibility.h
Normal file
32
gucc/tests/doctest_compatibility.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef DOCTEST_COMPATIBILITY_H
|
||||||
|
#define DOCTEST_COMPATIBILITY_H
|
||||||
|
|
||||||
|
#define DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
|
||||||
|
#define DOCTEST_THREAD_LOCAL // enable single-threaded builds on XCode 6/7 - https://github.com/onqtam/doctest/issues/172
|
||||||
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
|
// Catch doesn't require a semicolon after CAPTURE but doctest does
|
||||||
|
#undef CAPTURE
|
||||||
|
#define CAPTURE(x) DOCTEST_CAPTURE(x);
|
||||||
|
|
||||||
|
// Sections from Catch are called Subcases in doctest and don't work with std::string by default
|
||||||
|
#undef SUBCASE
|
||||||
|
#define SECTION(x) DOCTEST_SUBCASE(x)
|
||||||
|
|
||||||
|
// convenience macro around INFO since it doesn't support temporaries (it is optimized to avoid allocations for runtime speed)
|
||||||
|
#define INFO_WITH_TEMP_IMPL(x, var_name) const auto var_name = x; INFO(var_name) // lvalue!
|
||||||
|
#define INFO_WITH_TEMP(x) INFO_WITH_TEMP_IMPL(x, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
|
||||||
|
|
||||||
|
// doctest doesn't support THROWS_WITH for std::string out of the box (has to include <string>...)
|
||||||
|
#define CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, var_name) \
|
||||||
|
do { \
|
||||||
|
std::string var_name = str; \
|
||||||
|
CHECK_THROWS_WITH(expr, var_name.c_str()); \
|
||||||
|
} while (false)
|
||||||
|
#define CHECK_THROWS_WITH_STD_STR(expr, str) \
|
||||||
|
CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
|
||||||
|
|
||||||
|
// Catch does this by default
|
||||||
|
using doctest::Approx;
|
||||||
|
|
||||||
|
#endif
|
@ -1,103 +1,111 @@
|
|||||||
|
doctest_main_lib = static_library('doctest_main',
|
||||||
|
sources : [
|
||||||
|
'unit.cpp',
|
||||||
|
],
|
||||||
|
include_directories : [include_directories('.')],
|
||||||
|
dependencies: doctest
|
||||||
|
)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-initcpio',
|
'test-initcpio',
|
||||||
files('unit-initcpio.cpp'),
|
files('unit-initcpio.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-pacmanconf',
|
'test-pacmanconf',
|
||||||
files('unit-pacmanconf.cpp'),
|
files('unit-pacmanconf.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-fstab_gen',
|
'test-fstab_gen',
|
||||||
files('unit-fstab_gen.cpp'),
|
files('unit-fstab_gen.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-crypttab_gen',
|
'test-crypttab_gen',
|
||||||
files('unit-crypttab_gen.cpp'),
|
files('unit-crypttab_gen.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-grub_config_gen',
|
'test-grub_config_gen',
|
||||||
files('unit-grub_config_gen.cpp'),
|
files('unit-grub_config_gen.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-mtab',
|
'test-mtab',
|
||||||
files('unit-mtab.cpp'),
|
files('unit-mtab.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-locale',
|
'test-locale',
|
||||||
files('unit-locale.cpp'),
|
files('unit-locale.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-package_profiles',
|
'test-package_profiles',
|
||||||
files('unit-package_profiles.cpp'),
|
files('unit-package_profiles.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-fetch_file',
|
'test-fetch_file',
|
||||||
files('unit-fetch_file.cpp'),
|
files('unit-fetch_file.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-kernel_params',
|
'test-kernel_params',
|
||||||
files('unit-kernel_params.cpp'),
|
files('unit-kernel_params.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-btrfs',
|
'test-btrfs',
|
||||||
files('unit-btrfs.cpp'),
|
files('unit-btrfs.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-refind_config_gen',
|
'test-refind_config_gen',
|
||||||
files('unit-refind_config_gen.cpp'),
|
files('unit-refind_config_gen.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'test-refind_extra_kern_strings',
|
'test-refind_extra_kern_strings',
|
||||||
files('unit-refind_extra_kern_strings.cpp'),
|
files('unit-refind_extra_kern_strings.cpp'),
|
||||||
dependencies: deps,
|
dependencies: [deps, doctest],
|
||||||
link_with: [gucc_lib],
|
link_with: [gucc_lib, doctest_main_lib],
|
||||||
include_directories: [include_directories('../include')],
|
include_directories: [include_directories('../include')],
|
||||||
install: false)
|
install: false)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/btrfs.hpp"
|
#include "gucc/btrfs.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -13,7 +13,8 @@
|
|||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("BTRFS test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -28,7 +29,7 @@ int main() {
|
|||||||
// gucc::fs::BtrfsSubvolume{.subvolume = "/@snapshots"sv, .mountpoint = "/.snapshots"sv},
|
// gucc::fs::BtrfsSubvolume{.subvolume = "/@snapshots"sv, .mountpoint = "/.snapshots"sv},
|
||||||
};
|
};
|
||||||
|
|
||||||
// btrfs with subvolumes
|
SECTION("btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
||||||
@ -40,11 +41,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions.size() == 4);
|
REQUIRE(partitions.size() == 4);
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// invalid btrfs with subvolumes
|
SECTION("invalid btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@home"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@home"s},
|
||||||
@ -56,11 +57,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@cache"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@cache"s},
|
||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions.size() == 3);
|
REQUIRE(partitions.size() == 3);
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// invalid (without root part) btrfs with subvolumes
|
SECTION("invalid (without root part) btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@home"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@home"s},
|
||||||
@ -72,11 +73,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@cache"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@cache"s},
|
||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions.size() == 3);
|
REQUIRE(partitions.size() == 3);
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// btrfs without subvolumes
|
SECTION("btrfs without subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -86,11 +87,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(gucc::fs::btrfs_append_subvolumes(partitions, {}));
|
REQUIRE(gucc::fs::btrfs_append_subvolumes(partitions, {}));
|
||||||
assert(partitions.size() == 2);
|
REQUIRE(partitions.size() == 2);
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// luks xfs
|
SECTION("luks xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
||||||
@ -102,10 +103,10 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "linuxswap"s, .mountpoint = ""s, .uuid_str = ""s, .device = "/dev/nvme0n1p3"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "linuxswap"s, .mountpoint = ""s, .uuid_str = ""s, .device = "/dev/nvme0n1p3"s, .mount_opts = "defaults,noatime"s},
|
||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// valid zfs
|
SECTION("valid zfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -119,10 +120,10 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/var/cache"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(!gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes
|
SECTION("luks btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> expected_partitions{
|
const std::vector<gucc::fs::Partition> expected_partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -134,8 +135,8 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
assert(gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
REQUIRE(gucc::fs::btrfs_append_subvolumes(partitions, subvolumes));
|
||||||
assert(partitions.size() == 4);
|
REQUIRE(partitions.size() == 4);
|
||||||
assert(partitions == expected_partitions);
|
REQUIRE(partitions == expected_partitions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/crypttab.hpp"
|
#include "gucc/crypttab.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -32,7 +32,8 @@ static constexpr auto CRYPTTAB_UNENCR_BOOT_TEST = R"(# Configuration for encrypt
|
|||||||
luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f none
|
luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f none
|
||||||
)"sv;
|
)"sv;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("crypttab gen test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -44,7 +45,7 @@ int main() {
|
|||||||
const auto& btrfs_mountopts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s;
|
const auto& btrfs_mountopts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s;
|
||||||
const auto& xfs_mountopts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s;
|
const auto& xfs_mountopts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s;
|
||||||
|
|
||||||
// btrfs with subvolumes
|
SECTION("btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = uuid_str, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = uuid_str, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@"s},
|
||||||
@ -60,18 +61,18 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s, .luks_mapper_name = "", .luks_uuid = ""},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s, .luks_mapper_name = "", .luks_uuid = ""},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
||||||
}
|
}
|
||||||
// basic xfs
|
SECTION("basic xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = xfs_mountopts, .luks_mapper_name = ""},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = xfs_mountopts, .luks_mapper_name = ""},
|
||||||
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s, .luks_uuid = ""},
|
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s, .luks_uuid = ""},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
||||||
}
|
}
|
||||||
// luks xfs
|
SECTION("luks xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = xfs_mountopts, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = xfs_mountopts, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -79,9 +80,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
||||||
}
|
}
|
||||||
// zfs
|
SECTION("zfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -90,9 +91,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_EMPTY_TEST);
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes
|
SECTION("luks btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -101,9 +102,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes {shuffled}
|
SECTION("luks btrfs with subvolumes {shuffled}")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@home"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/home"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@home"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -112,7 +113,7 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@cache"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/var/cache"s, .device = "/dev/nvme0n1p1"s, .mount_opts = btrfs_mountopts, .subvolume = "/@cache"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
};
|
};
|
||||||
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
const auto& crypttab_content = gucc::fs::generate_crypttab_content(partitions, "luks"sv);
|
||||||
assert(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
REQUIRE(crypttab_content == CRYPTTAB_UNENCR_BOOT_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/fetch_file.hpp"
|
#include "gucc/fetch_file.hpp"
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
@ -11,35 +11,37 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("fetch file test")
|
||||||
// existing remote url, non existent fallback url
|
{
|
||||||
static constexpr std::string_view LICENSE_PATH = GUCC_TOP_DIR "/LICENSE";
|
static constexpr std::string_view LICENSE_PATH = GUCC_TOP_DIR "/LICENSE";
|
||||||
|
|
||||||
|
SECTION("existing remote url, non existent fallback url")
|
||||||
{
|
{
|
||||||
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LICENSE"sv;
|
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LICENSE"sv;
|
||||||
|
|
||||||
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit");
|
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit");
|
||||||
assert(file_content);
|
REQUIRE(file_content);
|
||||||
assert(!file_content->empty());
|
REQUIRE(!file_content->empty());
|
||||||
|
|
||||||
const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH);
|
const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH);
|
||||||
assert(file_content == expected_file_content);
|
REQUIRE(file_content == expected_file_content);
|
||||||
}
|
}
|
||||||
// non existent remote url, existing fallback url
|
SECTION("non existent remote url, existing fallback url")
|
||||||
{
|
{
|
||||||
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv;
|
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv;
|
||||||
|
|
||||||
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, fmt::format("file://{}", LICENSE_PATH));
|
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, fmt::format("file://{}", LICENSE_PATH));
|
||||||
assert(file_content);
|
REQUIRE(file_content);
|
||||||
assert(!file_content->empty());
|
REQUIRE(!file_content->empty());
|
||||||
|
|
||||||
const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH);
|
const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH);
|
||||||
assert(file_content == expected_file_content);
|
REQUIRE(file_content == expected_file_content);
|
||||||
}
|
}
|
||||||
// non existent remote url, non existent fallback url
|
SECTION("non existent remote url, non existent fallback url")
|
||||||
{
|
{
|
||||||
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv;
|
static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv;
|
||||||
|
|
||||||
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit");
|
const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit");
|
||||||
assert(!file_content);
|
REQUIRE(!file_content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/fstab.hpp"
|
#include "gucc/fstab.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -82,7 +82,8 @@ UUID=8EFB-4B84 /boot vfat defaults,noatim
|
|||||||
|
|
||||||
)"sv;
|
)"sv;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("fstab gen test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -90,7 +91,7 @@ int main() {
|
|||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
gucc::logger::set_logger(logger);
|
gucc::logger::set_logger(logger);
|
||||||
|
|
||||||
// btrfs with subvolumes
|
SECTION("btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
||||||
@ -99,18 +100,18 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
||||||
assert(fstab_content == FSTAB_BTRFS_TEST);
|
REQUIRE(fstab_content == FSTAB_BTRFS_TEST);
|
||||||
}
|
}
|
||||||
// basic xfs
|
SECTION("basic xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
||||||
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
||||||
assert(fstab_content == FSTAB_XFS_TEST);
|
REQUIRE(fstab_content == FSTAB_XFS_TEST);
|
||||||
}
|
}
|
||||||
// luks xfs
|
SECTION("luks xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
||||||
@ -118,9 +119,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
||||||
assert(fstab_content == FSTAB_LUKS_XFS_TEST);
|
REQUIRE(fstab_content == FSTAB_LUKS_XFS_TEST);
|
||||||
}
|
}
|
||||||
// zfs
|
SECTION("zfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -129,9 +130,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
||||||
assert(fstab_content == FSTAB_ZFS_TEST);
|
REQUIRE(fstab_content == FSTAB_ZFS_TEST);
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes
|
SECTION("luks btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -140,6 +141,6 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
const auto& fstab_content = gucc::fs::generate_fstab_content(partitions);
|
||||||
assert(fstab_content == FSTAB_LUKS_BTRFS_TEST);
|
REQUIRE(fstab_content == FSTAB_LUKS_BTRFS_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/bootloader.hpp"
|
#include "gucc/bootloader.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -114,7 +114,8 @@ inline auto filtered_res(std::string_view content) noexcept -> std::string {
|
|||||||
return result + '\n';
|
return result + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("grub config gen test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -122,13 +123,13 @@ int main() {
|
|||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
gucc::logger::set_logger(logger);
|
gucc::logger::set_logger(logger);
|
||||||
|
|
||||||
// default config
|
SECTION("default config")
|
||||||
{
|
{
|
||||||
const gucc::bootloader::GrubConfig grub_config{};
|
const gucc::bootloader::GrubConfig grub_config{};
|
||||||
const auto& grub_config_content = gucc::bootloader::gen_grub_config(grub_config);
|
const auto& grub_config_content = gucc::bootloader::gen_grub_config(grub_config);
|
||||||
assert(grub_config_content == GRUB_DEFAULTS_TEST);
|
REQUIRE(grub_config_content == GRUB_DEFAULTS_TEST);
|
||||||
}
|
}
|
||||||
// optionals set
|
SECTION("optionals set")
|
||||||
{
|
{
|
||||||
const gucc::bootloader::GrubConfig grub_config{
|
const gucc::bootloader::GrubConfig grub_config{
|
||||||
.default_entry = "saved"s,
|
.default_entry = "saved"s,
|
||||||
@ -155,6 +156,6 @@ int main() {
|
|||||||
.disable_os_prober = false,
|
.disable_os_prober = false,
|
||||||
};
|
};
|
||||||
const auto& grub_config_content = filtered_res(gucc::bootloader::gen_grub_config(grub_config));
|
const auto& grub_config_content = filtered_res(gucc::bootloader::gen_grub_config(grub_config));
|
||||||
assert(grub_config_content == GRUB_OPTIONALS_TEST);
|
REQUIRE(grub_config_content == GRUB_OPTIONALS_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/initcpio.hpp"
|
#include "gucc/initcpio.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -28,6 +29,20 @@ FILES=()
|
|||||||
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)
|
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
static constexpr auto MKINITCPIO_MODIFY_STR = R"(
|
||||||
|
# MODULES
|
||||||
|
MODULES=(radeon crc32c-intel)
|
||||||
|
|
||||||
|
# BINARIES
|
||||||
|
BINARIES=()
|
||||||
|
|
||||||
|
# FILES
|
||||||
|
FILES=()
|
||||||
|
|
||||||
|
# HOOKS
|
||||||
|
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck btrfs usr lvm2 zfs)
|
||||||
|
)";
|
||||||
|
|
||||||
static constexpr auto MKINITCPIO_INVALID_TEST = R"(
|
static constexpr auto MKINITCPIO_INVALID_TEST = R"(
|
||||||
# MODULES
|
# MODULES
|
||||||
MODULES=()
|
MODULES=()
|
||||||
@ -58,7 +73,8 @@ FILES=()
|
|||||||
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck btrfs usr lvm2 zfs)
|
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck btrfs usr lvm2 zfs)
|
||||||
)";
|
)";
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("initcpio test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -70,80 +86,108 @@ int main() {
|
|||||||
|
|
||||||
static constexpr std::string_view filename{"/tmp/mkinitcpio.conf"};
|
static constexpr std::string_view filename{"/tmp/mkinitcpio.conf"};
|
||||||
|
|
||||||
// Open mkinitcpio file for writing.
|
SECTION("parse file")
|
||||||
std::ofstream mkinitcpio_file{filename.data()};
|
{
|
||||||
assert(mkinitcpio_file.is_open());
|
// setup data.
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, MKINITCPIO_STR));
|
||||||
// Setup mkinitcpio file.
|
|
||||||
mkinitcpio_file << MKINITCPIO_STR;
|
|
||||||
mkinitcpio_file.close();
|
|
||||||
|
|
||||||
auto initcpio = detail::Initcpio{filename};
|
auto initcpio = detail::Initcpio{filename};
|
||||||
|
REQUIRE(initcpio.parse_file());
|
||||||
|
|
||||||
// Insert data.
|
const std::vector<std::string> default_hooks{
|
||||||
initcpio.append_module("radeon");
|
"base", "udev", "autodetect", "modconf", "block", "filesystems", "keyboard", "fsck"};
|
||||||
initcpio.append_hook("btrfs");
|
|
||||||
initcpio.append_module("crc32c-intel");
|
REQUIRE_EQ(initcpio.hooks.size(), default_hooks.size());
|
||||||
initcpio.append_hooks({"usr", "lvm2", "zfs"});
|
REQUIRE_EQ(initcpio.hooks, default_hooks);
|
||||||
|
REQUIRE(initcpio.modules.empty());
|
||||||
|
REQUIRE(initcpio.files.empty());
|
||||||
|
}
|
||||||
|
SECTION("insert data")
|
||||||
|
{
|
||||||
|
// setup data.
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, MKINITCPIO_STR));
|
||||||
|
|
||||||
|
auto initcpio = detail::Initcpio{filename};
|
||||||
|
REQUIRE(initcpio.append_module("radeon"));
|
||||||
|
REQUIRE(initcpio.append_hook("btrfs"));
|
||||||
|
REQUIRE(initcpio.append_module("crc32c-intel"));
|
||||||
|
REQUIRE(initcpio.append_hooks({"usr", "lvm2", "zfs"}));
|
||||||
|
|
||||||
|
const std::vector<std::string> expected_hooks{
|
||||||
|
"base", "udev", "autodetect", "modconf", "block", "filesystems", "keyboard", "fsck", "btrfs", "usr", "lvm2", "zfs"};
|
||||||
|
|
||||||
|
const std::vector<std::string> expected_modules{
|
||||||
|
"radeon", "crc32c-intel"};
|
||||||
|
|
||||||
|
REQUIRE_EQ(initcpio.hooks.size(), expected_hooks.size());
|
||||||
|
REQUIRE_EQ(initcpio.hooks, expected_hooks);
|
||||||
|
REQUIRE_EQ(initcpio.modules.size(), expected_modules.size());
|
||||||
|
REQUIRE_EQ(initcpio.modules, expected_modules);
|
||||||
|
REQUIRE(initcpio.files.empty());
|
||||||
|
|
||||||
// Write data.
|
// Write data.
|
||||||
assert(initcpio.write());
|
REQUIRE(initcpio.write());
|
||||||
|
}
|
||||||
|
SECTION("checking insertion of equal items")
|
||||||
|
{
|
||||||
|
// setup data.
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, MKINITCPIO_MODIFY_STR));
|
||||||
|
|
||||||
// Checking insertion of equal items
|
auto initcpio = detail::Initcpio{filename};
|
||||||
assert(!initcpio.append_module("radeon"));
|
REQUIRE(initcpio.parse_file());
|
||||||
assert(!initcpio.append_hook("btrfs"));
|
|
||||||
assert(!initcpio.append_module("crc32c-intel"));
|
REQUIRE(!initcpio.append_module("radeon"));
|
||||||
assert(!initcpio.insert_hook("btrfs", {"usr", "lvm2", "zfs"}));
|
REQUIRE(!initcpio.append_hook("btrfs"));
|
||||||
|
REQUIRE(!initcpio.append_module("crc32c-intel"));
|
||||||
|
REQUIRE(!initcpio.insert_hook("btrfs", {"usr", "lvm2", "zfs"}));
|
||||||
|
|
||||||
// Write data.
|
// Write data.
|
||||||
assert(initcpio.write());
|
REQUIRE(initcpio.write());
|
||||||
|
}
|
||||||
|
SECTION("check if file is equal to test data")
|
||||||
|
{
|
||||||
|
// setup data.
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, MKINITCPIO_MODIFY_STR));
|
||||||
|
|
||||||
// Check if file is equal to test data.
|
|
||||||
// "\n# MODULES\nMODULES=(crc32c-intel)\n\n# BINARIES\nBINARIES=()\n\n# FILES\nFILES=()\n\n# HOOKS\nHOOKS=(base usr lvm2 zfs)"\n
|
// "\n# MODULES\nMODULES=(crc32c-intel)\n\n# BINARIES\nBINARIES=()\n\n# FILES\nFILES=()\n\n# HOOKS\nHOOKS=(base usr lvm2 zfs)"\n
|
||||||
const auto& file_content = file_utils::read_whole_file(filename);
|
const auto& file_content = file_utils::read_whole_file(filename);
|
||||||
assert(file_content == MKINITCPIO_TEST);
|
REQUIRE_EQ(file_content, MKINITCPIO_TEST);
|
||||||
|
}
|
||||||
|
SECTION("check invalid file")
|
||||||
|
{
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, MKINITCPIO_INVALID_TEST));
|
||||||
|
|
||||||
|
auto initcpio = detail::Initcpio{filename};
|
||||||
|
REQUIRE(initcpio.parse_file());
|
||||||
|
|
||||||
|
REQUIRE(initcpio.modules.empty());
|
||||||
|
REQUIRE(initcpio.files.empty());
|
||||||
|
REQUIRE(initcpio.hooks.empty());
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(filename);
|
fs::remove(filename);
|
||||||
|
}
|
||||||
|
SECTION("check empty file")
|
||||||
|
{
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, ""));
|
||||||
|
|
||||||
// check invalid file
|
auto initcpio = detail::Initcpio{filename};
|
||||||
mkinitcpio_file = std::ofstream{filename.data()};
|
REQUIRE(!initcpio.parse_file());
|
||||||
assert(mkinitcpio_file.is_open());
|
REQUIRE(!initcpio.write());
|
||||||
|
|
||||||
mkinitcpio_file << MKINITCPIO_INVALID_TEST;
|
|
||||||
mkinitcpio_file.close();
|
|
||||||
|
|
||||||
initcpio = detail::Initcpio{filename};
|
|
||||||
assert(initcpio.parse_file());
|
|
||||||
|
|
||||||
assert(initcpio.modules.empty());
|
|
||||||
assert(initcpio.files.empty());
|
|
||||||
assert(initcpio.hooks.empty());
|
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(filename);
|
fs::remove(filename);
|
||||||
|
}
|
||||||
// check empty file
|
SECTION("check write to nonexistent file")
|
||||||
mkinitcpio_file = std::ofstream{filename.data()};
|
{
|
||||||
assert(mkinitcpio_file.is_open());
|
auto initcpio = detail::Initcpio{"/path/to/non/exist_file.conf"};
|
||||||
|
REQUIRE(!initcpio.parse_file());
|
||||||
mkinitcpio_file << "";
|
REQUIRE(!initcpio.write());
|
||||||
mkinitcpio_file.close();
|
}
|
||||||
|
SECTION("check write to root file")
|
||||||
initcpio = detail::Initcpio{filename};
|
{
|
||||||
assert(!initcpio.parse_file());
|
auto initcpio = detail::Initcpio{"/etc/mtab"};
|
||||||
assert(!initcpio.write());
|
REQUIRE(!initcpio.parse_file());
|
||||||
|
REQUIRE(!initcpio.write());
|
||||||
// Cleanup.
|
}
|
||||||
fs::remove(filename);
|
|
||||||
|
|
||||||
// check write to nonexistent file
|
|
||||||
initcpio = detail::Initcpio{"/path/to/non/exist_file.conf"};
|
|
||||||
assert(!initcpio.parse_file());
|
|
||||||
assert(!initcpio.write());
|
|
||||||
|
|
||||||
// check write to root file
|
|
||||||
initcpio = detail::Initcpio{"/etc/mtab"};
|
|
||||||
assert(!initcpio.parse_file());
|
|
||||||
assert(!initcpio.write());
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/kernel_params.hpp"
|
#include "gucc/kernel_params.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -13,7 +13,8 @@
|
|||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("kernel params get test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -23,7 +24,7 @@ int main() {
|
|||||||
|
|
||||||
static constexpr auto DEFAULT_KERNEL_PARAMS = "quiet splash"sv;
|
static constexpr auto DEFAULT_KERNEL_PARAMS = "quiet splash"sv;
|
||||||
|
|
||||||
// btrfs with subvolumes
|
SECTION("btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s},
|
||||||
@ -32,40 +33,40 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 5);
|
REQUIRE(kernel_params->size() == 5);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "rootflags=subvol=/@", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "rootflags=subvol=/@", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
||||||
}
|
}
|
||||||
// invalid xfs (empty uuid)
|
SECTION("invalid xfs (empty uuid)")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
||||||
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(!kernel_params.has_value());
|
REQUIRE(!kernel_params.has_value());
|
||||||
}
|
}
|
||||||
// invalid xfs (without root partition)
|
SECTION("invalid xfs (without root partition)")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/home"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/home"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
||||||
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(!kernel_params.has_value());
|
REQUIRE(!kernel_params.has_value());
|
||||||
}
|
}
|
||||||
// basic xfs
|
SECTION("basic xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
||||||
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat16"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 4);
|
REQUIRE(kernel_params->size() == 4);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
||||||
}
|
}
|
||||||
// swap xfs
|
SECTION("swap xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s},
|
||||||
@ -73,11 +74,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 5);
|
REQUIRE(kernel_params->size() == 5);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"}));
|
||||||
}
|
}
|
||||||
// luks xfs
|
SECTION("luks xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
||||||
@ -85,11 +86,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 5);
|
REQUIRE(kernel_params->size() == 5);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device"}));
|
||||||
}
|
}
|
||||||
// luks swap xfs
|
SECTION("luks swap xfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
gucc::fs::Partition{.fstype = "xfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,lazytime,noatime,attr2,inode64,logbsize=256k,noquota"s, .luks_mapper_name = "luks_device"s, .luks_uuid = "00e1b836-81b6-433f-83ca-0fd373e3cd50"s},
|
||||||
@ -97,11 +98,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 6);
|
REQUIRE(kernel_params->size() == 6);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device", "resume=/dev/mapper/luks_swap_device"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device", "resume=/dev/mapper/luks_swap_device"}));
|
||||||
}
|
}
|
||||||
// invalid zfs
|
SECTION("invalid zfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -110,9 +111,9 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(!kernel_params.has_value());
|
REQUIRE(!kernel_params.has_value());
|
||||||
}
|
}
|
||||||
// valid zfs
|
SECTION("valid zfs")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
gucc::fs::Partition{.fstype = "zfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s},
|
||||||
@ -121,11 +122,11 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "vfat"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS, "zpcachyos/ROOT");
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS, "zpcachyos/ROOT");
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 5);
|
REQUIRE(kernel_params->size() == 5);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=ZFS=zpcachyos/ROOT", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "root=ZFS=zpcachyos/ROOT", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes
|
SECTION("luks btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<gucc::fs::Partition> partitions{
|
const std::vector<gucc::fs::Partition> partitions{
|
||||||
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
gucc::fs::Partition{.fstype = "btrfs"s, .mountpoint = "/"s, .uuid_str = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .device = "/dev/nvme0n1p1"s, .mount_opts = "defaults,noatime,compress=zstd,space_cache=v2,commit=120"s, .subvolume = "/@"s, .luks_mapper_name = "luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s, .luks_uuid = "6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"s},
|
||||||
@ -134,8 +135,8 @@ int main() {
|
|||||||
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
gucc::fs::Partition{.fstype = "fat32"s, .mountpoint = "/boot"s, .uuid_str = "8EFB-4B84"s, .device = "/dev/nvme0n1p2"s, .mount_opts = "defaults,noatime"s},
|
||||||
};
|
};
|
||||||
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
const auto& kernel_params = gucc::fs::get_kernel_params(partitions, DEFAULT_KERNEL_PARAMS);
|
||||||
assert(kernel_params.has_value());
|
REQUIRE(kernel_params.has_value());
|
||||||
assert(kernel_params->size() == 6);
|
REQUIRE(kernel_params->size() == 6);
|
||||||
assert((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "rootflags=subvol=/@", "cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
REQUIRE((*kernel_params == std::vector<std::string>{"quiet", "splash", "rw", "rootflags=subvol=/@", "cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/locale.hpp"
|
#include "gucc/locale.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@ -42,7 +42,8 @@ inline auto filtered_res(std::string_view content) noexcept -> std::string {
|
|||||||
return result + '\n';
|
return result + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("locale test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -56,21 +57,23 @@ int main() {
|
|||||||
static constexpr std::string_view dest_locale_gen{"/tmp/test-locale-unittest/etc/locale.gen"};
|
static constexpr std::string_view dest_locale_gen{"/tmp/test-locale-unittest/etc/locale.gen"};
|
||||||
static constexpr std::string_view dest_locale_conf{"/tmp/test-locale-unittest/etc/locale.conf"};
|
static constexpr std::string_view dest_locale_conf{"/tmp/test-locale-unittest/etc/locale.conf"};
|
||||||
|
|
||||||
|
SECTION("set test locale")
|
||||||
|
{
|
||||||
fs::create_directories(folder_path);
|
fs::create_directories(folder_path);
|
||||||
|
|
||||||
fs::copy_file(GUCC_TEST_DIR "/files/locale.gen", dest_locale_gen, fs::copy_options::overwrite_existing);
|
fs::copy_file(GUCC_TEST_DIR "/files/locale.gen", dest_locale_gen, fs::copy_options::overwrite_existing);
|
||||||
|
|
||||||
// set test locale.
|
REQUIRE(gucc::locale::prepare_locale_set("ru_RU.UTF-8"sv, folder_testpath));
|
||||||
assert(gucc::locale::prepare_locale_set("ru_RU.UTF-8"sv, folder_testpath));
|
|
||||||
|
|
||||||
auto locale_conf_content = gucc::file_utils::read_whole_file(dest_locale_conf);
|
auto locale_conf_content = gucc::file_utils::read_whole_file(dest_locale_conf);
|
||||||
assert(locale_conf_content == LOCALE_CONF_TEST);
|
REQUIRE_EQ(locale_conf_content, LOCALE_CONF_TEST);
|
||||||
|
|
||||||
auto locale_gen_content = filtered_res(gucc::file_utils::read_whole_file(dest_locale_gen));
|
auto locale_gen_content = filtered_res(gucc::file_utils::read_whole_file(dest_locale_gen));
|
||||||
assert(locale_gen_content == LOCALE_GEN_TEST);
|
REQUIRE_EQ(locale_gen_content, LOCALE_GEN_TEST);
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove_all(folder_testpath);
|
fs::remove_all(folder_testpath);
|
||||||
|
}
|
||||||
assert(!gucc::locale::prepare_locale_set("ru_RU.UTF-8"sv, folder_testpath));
|
SECTION("set locale at invalid file path")
|
||||||
|
{
|
||||||
|
REQUIRE(!gucc::locale::prepare_locale_set("ru_RU.UTF-8"sv, folder_testpath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "gucc/mtab.hpp"
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include "gucc/mtab.hpp"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -107,78 +107,79 @@ sys /tmp/calamares-root-q_z5rdlx/sys sysfs rw,noatime 0 0
|
|||||||
efivarfs /tmp/calamares-root-q_z5rdlx/sys/firmware/efi/efivars efivarfs rw,noatime 0 0
|
efivarfs /tmp/calamares-root-q_z5rdlx/sys/firmware/efi/efivars efivarfs rw,noatime 0 0
|
||||||
)"sv;
|
)"sv;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("mtab test")
|
||||||
// running system
|
{
|
||||||
|
SECTION("running system")
|
||||||
{
|
{
|
||||||
const auto& mtab_entries = gucc::mtab::parse_mtab_content(MTAB_RUNNING_SYSTEM_TEST, "/mnt"sv);
|
const auto& mtab_entries = gucc::mtab::parse_mtab_content(MTAB_RUNNING_SYSTEM_TEST, "/mnt"sv);
|
||||||
assert(mtab_entries.size() == 2);
|
REQUIRE(mtab_entries.size() == 2);
|
||||||
assert(mtab_entries[0].device == "/dev/nvme0n1p3");
|
REQUIRE(mtab_entries[0].device == "/dev/nvme0n1p3");
|
||||||
assert(mtab_entries[0].mountpoint == "/mnt");
|
REQUIRE(mtab_entries[0].mountpoint == "/mnt");
|
||||||
assert(mtab_entries[1].device == "/dev/nvme0n1p1");
|
REQUIRE(mtab_entries[1].device == "/dev/nvme0n1p1");
|
||||||
assert(mtab_entries[1].mountpoint == "/mnt/boot");
|
REQUIRE(mtab_entries[1].mountpoint == "/mnt/boot");
|
||||||
}
|
}
|
||||||
// live iso system
|
SECTION("live iso system")
|
||||||
{
|
{
|
||||||
static constexpr std::string_view filename{"/tmp/mtab.conf"};
|
static constexpr std::string_view filename{"/tmp/mtab.conf"};
|
||||||
// Open mtab file for writing.
|
// Open mtab file for writing.
|
||||||
std::ofstream mtab_file{filename.data()};
|
std::ofstream mtab_file{filename.data()};
|
||||||
assert(mtab_file.is_open());
|
REQUIRE(mtab_file.is_open());
|
||||||
|
|
||||||
// Setup mtab file.
|
// Setup mtab file.
|
||||||
mtab_file << MTAB_LIVE_ISO_TEST;
|
mtab_file << MTAB_LIVE_ISO_TEST;
|
||||||
mtab_file.close();
|
mtab_file.close();
|
||||||
|
|
||||||
const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename);
|
const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename);
|
||||||
assert(mtab_entries.has_value());
|
REQUIRE(mtab_entries.has_value());
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(filename);
|
fs::remove(filename);
|
||||||
|
|
||||||
const auto& entries = *mtab_entries;
|
const auto& entries = *mtab_entries;
|
||||||
assert(entries.size() == 14);
|
REQUIRE(entries.size() == 14);
|
||||||
assert(entries[0].device == "/dev/sda2");
|
REQUIRE(entries[0].device == "/dev/sda2");
|
||||||
assert(entries[0].mountpoint == "/tmp/calamares-root-q_z5rdlx");
|
REQUIRE(entries[0].mountpoint == "/tmp/calamares-root-q_z5rdlx");
|
||||||
assert(entries[1].device == "/dev/sda2");
|
REQUIRE(entries[1].device == "/dev/sda2");
|
||||||
assert(entries[1].mountpoint == "/tmp/calamares-root-q_z5rdlx/home");
|
REQUIRE(entries[1].mountpoint == "/tmp/calamares-root-q_z5rdlx/home");
|
||||||
assert(entries[2].device == "/dev/sda2");
|
REQUIRE(entries[2].device == "/dev/sda2");
|
||||||
assert(entries[2].mountpoint == "/tmp/calamares-root-q_z5rdlx/root");
|
REQUIRE(entries[2].mountpoint == "/tmp/calamares-root-q_z5rdlx/root");
|
||||||
assert(entries[3].device == "/dev/sda2");
|
REQUIRE(entries[3].device == "/dev/sda2");
|
||||||
assert(entries[3].mountpoint == "/tmp/calamares-root-q_z5rdlx/srv");
|
REQUIRE(entries[3].mountpoint == "/tmp/calamares-root-q_z5rdlx/srv");
|
||||||
assert(entries[4].device == "/dev/sda2");
|
REQUIRE(entries[4].device == "/dev/sda2");
|
||||||
assert(entries[4].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/cache");
|
REQUIRE(entries[4].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/cache");
|
||||||
assert(entries[5].device == "/dev/sda2");
|
REQUIRE(entries[5].device == "/dev/sda2");
|
||||||
assert(entries[5].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/tmp");
|
REQUIRE(entries[5].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/tmp");
|
||||||
assert(entries[6].device == "/dev/sda2");
|
REQUIRE(entries[6].device == "/dev/sda2");
|
||||||
assert(entries[6].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/log");
|
REQUIRE(entries[6].mountpoint == "/tmp/calamares-root-q_z5rdlx/var/log");
|
||||||
assert(entries[7].device == "/dev/sda1");
|
REQUIRE(entries[7].device == "/dev/sda1");
|
||||||
assert(entries[7].mountpoint == "/tmp/calamares-root-q_z5rdlx/boot");
|
REQUIRE(entries[7].mountpoint == "/tmp/calamares-root-q_z5rdlx/boot");
|
||||||
|
|
||||||
assert(entries[8].device == "dev");
|
REQUIRE(entries[8].device == "dev");
|
||||||
assert(entries[8].mountpoint == "/tmp/calamares-root-q_z5rdlx/dev");
|
REQUIRE(entries[8].mountpoint == "/tmp/calamares-root-q_z5rdlx/dev");
|
||||||
assert(entries[9].device == "proc");
|
REQUIRE(entries[9].device == "proc");
|
||||||
assert(entries[9].mountpoint == "/tmp/calamares-root-q_z5rdlx/proc");
|
REQUIRE(entries[9].mountpoint == "/tmp/calamares-root-q_z5rdlx/proc");
|
||||||
assert(entries[10].device == "tmpfs");
|
REQUIRE(entries[10].device == "tmpfs");
|
||||||
assert(entries[10].mountpoint == "/tmp/calamares-root-q_z5rdlx/run");
|
REQUIRE(entries[10].mountpoint == "/tmp/calamares-root-q_z5rdlx/run");
|
||||||
assert(entries[11].device == "run");
|
REQUIRE(entries[11].device == "run");
|
||||||
assert(entries[11].mountpoint == "/tmp/calamares-root-q_z5rdlx/run/udev");
|
REQUIRE(entries[11].mountpoint == "/tmp/calamares-root-q_z5rdlx/run/udev");
|
||||||
assert(entries[12].device == "sys");
|
REQUIRE(entries[12].device == "sys");
|
||||||
assert(entries[12].mountpoint == "/tmp/calamares-root-q_z5rdlx/sys");
|
REQUIRE(entries[12].mountpoint == "/tmp/calamares-root-q_z5rdlx/sys");
|
||||||
assert(entries[13].device == "efivarfs");
|
REQUIRE(entries[13].device == "efivarfs");
|
||||||
assert(entries[13].mountpoint == "/tmp/calamares-root-q_z5rdlx/sys/firmware/efi/efivars");
|
REQUIRE(entries[13].mountpoint == "/tmp/calamares-root-q_z5rdlx/sys/firmware/efi/efivars");
|
||||||
}
|
}
|
||||||
// empty file
|
SECTION("empty file")
|
||||||
{
|
{
|
||||||
static constexpr std::string_view filename{"/tmp/mtab.conf"};
|
static constexpr std::string_view filename{"/tmp/mtab.conf"};
|
||||||
// Open mtab file for writing.
|
// Open mtab file for writing.
|
||||||
std::ofstream mtab_file{filename.data()};
|
std::ofstream mtab_file{filename.data()};
|
||||||
assert(mtab_file.is_open());
|
REQUIRE(mtab_file.is_open());
|
||||||
|
|
||||||
// Setup mtab file.
|
// Setup mtab file.
|
||||||
mtab_file << "";
|
mtab_file << "";
|
||||||
mtab_file.close();
|
mtab_file.close();
|
||||||
|
|
||||||
const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename);
|
const auto& mtab_entries = gucc::mtab::parse_mtab("/tmp/calamares-root-q_z5rdlx"sv, filename);
|
||||||
assert(!mtab_entries.has_value());
|
REQUIRE(!mtab_entries.has_value());
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(filename);
|
fs::remove(filename);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
#include "gucc/package_profiles.hpp"
|
#include "gucc/package_profiles.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@ -36,7 +36,8 @@ pacages = ["ca,"da","fa"
|
|||||||
packaes = ["cb","db",fb"]
|
packaes = ["cb","db",fb"]
|
||||||
)"sv;
|
)"sv;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("package profiles test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -44,40 +45,40 @@ int main() {
|
|||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
gucc::logger::set_logger(logger);
|
gucc::logger::set_logger(logger);
|
||||||
|
|
||||||
// valid profile
|
SECTION("valid profile")
|
||||||
{
|
{
|
||||||
auto base_profs = gucc::profile::parse_base_profiles(VALID_PROFILE_TEST);
|
auto base_profs = gucc::profile::parse_base_profiles(VALID_PROFILE_TEST);
|
||||||
assert(base_profs);
|
REQUIRE(base_profs);
|
||||||
assert((base_profs->base_packages == std::vector<std::string>{"a", "b"}));
|
REQUIRE((base_profs->base_packages == std::vector<std::string>{"a", "b"}));
|
||||||
assert((base_profs->base_desktop_packages == std::vector<std::string>{"c", "d", "f"}));
|
REQUIRE((base_profs->base_desktop_packages == std::vector<std::string>{"c", "d", "f"}));
|
||||||
|
|
||||||
auto base_desktop_profs = gucc::profile::parse_desktop_profiles(VALID_PROFILE_TEST);
|
auto base_desktop_profs = gucc::profile::parse_desktop_profiles(VALID_PROFILE_TEST);
|
||||||
assert(base_desktop_profs);
|
REQUIRE(base_desktop_profs);
|
||||||
assert(base_desktop_profs->size() == 2);
|
REQUIRE(base_desktop_profs->size() == 2);
|
||||||
assert(((*base_desktop_profs)[0].profile_name == "someprofile-1"));
|
REQUIRE(((*base_desktop_profs)[0].profile_name == "someprofile-1"));
|
||||||
assert(((*base_desktop_profs)[0].packages == std::vector<std::string>{"ca", "da", "fa"}));
|
REQUIRE(((*base_desktop_profs)[0].packages == std::vector<std::string>{"ca", "da", "fa"}));
|
||||||
assert(((*base_desktop_profs)[1].profile_name == "someprofile-2"));
|
REQUIRE(((*base_desktop_profs)[1].profile_name == "someprofile-2"));
|
||||||
assert(((*base_desktop_profs)[1].packages == std::vector<std::string>{"cb", "db", "fb"}));
|
REQUIRE(((*base_desktop_profs)[1].packages == std::vector<std::string>{"cb", "db", "fb"}));
|
||||||
|
|
||||||
auto net_profs = gucc::profile::parse_net_profiles(VALID_PROFILE_TEST);
|
auto net_profs = gucc::profile::parse_net_profiles(VALID_PROFILE_TEST);
|
||||||
assert(net_profs);
|
REQUIRE(net_profs);
|
||||||
assert((net_profs->base_profiles.base_packages == std::vector<std::string>{"a", "b"}));
|
REQUIRE((net_profs->base_profiles.base_packages == std::vector<std::string>{"a", "b"}));
|
||||||
assert((net_profs->base_profiles.base_desktop_packages == std::vector<std::string>{"c", "d", "f"}));
|
REQUIRE((net_profs->base_profiles.base_desktop_packages == std::vector<std::string>{"c", "d", "f"}));
|
||||||
assert(net_profs->desktop_profiles.size() == 2);
|
REQUIRE(net_profs->desktop_profiles.size() == 2);
|
||||||
assert((net_profs->desktop_profiles[0].profile_name == "someprofile-1"));
|
REQUIRE((net_profs->desktop_profiles[0].profile_name == "someprofile-1"));
|
||||||
assert((net_profs->desktop_profiles[0].packages == std::vector<std::string>{"ca", "da", "fa"}));
|
REQUIRE((net_profs->desktop_profiles[0].packages == std::vector<std::string>{"ca", "da", "fa"}));
|
||||||
assert((net_profs->desktop_profiles[1].profile_name == "someprofile-2"));
|
REQUIRE((net_profs->desktop_profiles[1].profile_name == "someprofile-2"));
|
||||||
assert((net_profs->desktop_profiles[1].packages == std::vector<std::string>{"cb", "db", "fb"}));
|
REQUIRE((net_profs->desktop_profiles[1].packages == std::vector<std::string>{"cb", "db", "fb"}));
|
||||||
}
|
}
|
||||||
// invalid profile
|
SECTION("invalid profile")
|
||||||
{
|
{
|
||||||
auto base_profs = gucc::profile::parse_base_profiles(INVALID_PROFILE_TEST);
|
auto base_profs = gucc::profile::parse_base_profiles(INVALID_PROFILE_TEST);
|
||||||
assert(!base_profs);
|
REQUIRE(!base_profs);
|
||||||
|
|
||||||
auto base_desktop_profs = gucc::profile::parse_desktop_profiles(INVALID_PROFILE_TEST);
|
auto base_desktop_profs = gucc::profile::parse_desktop_profiles(INVALID_PROFILE_TEST);
|
||||||
assert(!base_desktop_profs);
|
REQUIRE(!base_desktop_profs);
|
||||||
|
|
||||||
auto net_profs = gucc::profile::parse_net_profiles(INVALID_PROFILE_TEST);
|
auto net_profs = gucc::profile::parse_net_profiles(INVALID_PROFILE_TEST);
|
||||||
assert(!net_profs);
|
REQUIRE(!net_profs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/pacmanconf_repo.hpp"
|
#include "gucc/pacmanconf_repo.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -117,36 +118,39 @@ Include = /etc/pacman.d/mirrorlist
|
|||||||
Include = /etc/pacman.d/mirrorlist
|
Include = /etc/pacman.d/mirrorlist
|
||||||
)";
|
)";
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("pacman conf test")
|
||||||
|
{
|
||||||
using namespace gucc;
|
using namespace gucc;
|
||||||
|
|
||||||
static constexpr std::string_view filename{"/tmp/pacman.conf"};
|
static constexpr std::string_view filename{"/tmp/pacman.conf"};
|
||||||
|
|
||||||
// Open pacmanconf file for writing.
|
SECTION("get current repos")
|
||||||
std::ofstream pacmanconf_file{filename.data()};
|
{
|
||||||
assert(pacmanconf_file.is_open());
|
REQUIRE(file_utils::create_file_for_overwrite(filename, PACMANCONF_STR));
|
||||||
|
|
||||||
// Setup pacmanconf file.
|
|
||||||
pacmanconf_file << PACMANCONF_STR;
|
|
||||||
pacmanconf_file.close();
|
|
||||||
|
|
||||||
// Get current repos.
|
|
||||||
auto repo_list = detail::pacmanconf::get_repo_list(filename);
|
auto repo_list = detail::pacmanconf::get_repo_list(filename);
|
||||||
assert(!repo_list.empty());
|
REQUIRE(!repo_list.empty());
|
||||||
assert((repo_list == std::vector<std::string>{"[core]", "[extra]", "[community]", "[multilib]"}));
|
REQUIRE((repo_list == std::vector<std::string>{"[core]", "[extra]", "[community]", "[multilib]"}));
|
||||||
|
|
||||||
// Push repo.
|
|
||||||
assert(detail::pacmanconf::push_repos_front(filename, "[cachyos]\nInclude = /etc/pacman.d/cachyos-mirrorlist"));
|
|
||||||
|
|
||||||
// Check repo list after pushing repo.
|
|
||||||
repo_list = detail::pacmanconf::get_repo_list(filename);
|
|
||||||
assert(!repo_list.empty());
|
|
||||||
assert((repo_list == std::vector<std::string>{"[cachyos]", "[core]", "[extra]", "[community]", "[multilib]"}));
|
|
||||||
|
|
||||||
// Check if file is equal to test data.
|
|
||||||
const auto& file_content = file_utils::read_whole_file(filename);
|
|
||||||
assert(file_content == PACMANCONF_TEST);
|
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(filename);
|
fs::remove(filename);
|
||||||
|
}
|
||||||
|
SECTION("push repo")
|
||||||
|
{
|
||||||
|
REQUIRE(file_utils::create_file_for_overwrite(filename, PACMANCONF_STR));
|
||||||
|
|
||||||
|
REQUIRE(detail::pacmanconf::push_repos_front(filename, "[cachyos]\nInclude = /etc/pacman.d/cachyos-mirrorlist"));
|
||||||
|
|
||||||
|
// check repo list after pushing repo
|
||||||
|
auto repo_list = detail::pacmanconf::get_repo_list(filename);
|
||||||
|
REQUIRE(!repo_list.empty());
|
||||||
|
REQUIRE((repo_list == std::vector<std::string>{"[cachyos]", "[core]", "[extra]", "[community]", "[multilib]"}));
|
||||||
|
|
||||||
|
// check if file is equal to test data
|
||||||
|
const auto& file_content = file_utils::read_whole_file(filename);
|
||||||
|
REQUIRE(file_content == PACMANCONF_TEST);
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
fs::remove(filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/bootloader.hpp"
|
#include "gucc/bootloader.hpp"
|
||||||
#include "gucc/kernel_params.hpp"
|
#include "gucc/kernel_params.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -42,7 +42,8 @@ static constexpr auto REFIND_CONFIG_LUKS_SUBVOL_TEST = R"("Boot with standard op
|
|||||||
"Boot to single-user mode" "quiet splash rw rootflags=subvol=/@ cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
"Boot to single-user mode" "quiet splash rw rootflags=subvol=/@ cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f" single
|
||||||
)"sv;
|
)"sv;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("refind config gen test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -50,54 +51,54 @@ int main() {
|
|||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
gucc::logger::set_logger(logger);
|
gucc::logger::set_logger(logger);
|
||||||
|
|
||||||
// btrfs with subvolumes
|
SECTION("btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "rootflags=subvol=/@", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
"quiet", "splash", "rw", "rootflags=subvol=/@", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||||
|
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_SUBVOL_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_SUBVOL_TEST);
|
||||||
}
|
}
|
||||||
// basic xfs
|
SECTION("basic xfs")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_TEST);
|
||||||
}
|
}
|
||||||
// swap xfs
|
SECTION("swap xfs")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"};
|
"quiet", "splash", "rw", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "resume=UUID=59848b1b-c6be-48f4-b3e1-48179ea72dec"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_SWAP_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_SWAP_TEST);
|
||||||
}
|
}
|
||||||
// luks xfs
|
SECTION("luks xfs")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device"};
|
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_LUKS_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_LUKS_TEST);
|
||||||
}
|
}
|
||||||
// luks swap xfs
|
SECTION("luks swap xfs")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device", "resume=/dev/mapper/luks_swap_device"};
|
"quiet", "splash", "rw", "cryptdevice=UUID=00e1b836-81b6-433f-83ca-0fd373e3cd50:luks_device", "root=/dev/mapper/luks_device", "resume=/dev/mapper/luks_swap_device"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_LUKS_SWAP_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_LUKS_SWAP_TEST);
|
||||||
}
|
}
|
||||||
// valid zfs
|
SECTION("valid zfs")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "root=ZFS=zpcachyos/ROOT", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
"quiet", "splash", "rw", "root=ZFS=zpcachyos/ROOT", "root=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_ZFS_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_ZFS_TEST);
|
||||||
}
|
}
|
||||||
// luks btrfs with subvolumes
|
SECTION("luks btrfs with subvolumes")
|
||||||
{
|
{
|
||||||
const std::vector<std::string> kernel_params{
|
const std::vector<std::string> kernel_params{
|
||||||
"quiet", "splash", "rw", "rootflags=subvol=/@", "cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
"quiet", "splash", "rw", "rootflags=subvol=/@", "cryptdevice=UUID=6bdb3301-8efb-4b84-b0b7-4caeef26fd6f:luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f", "root=/dev/mapper/luks-6bdb3301-8efb-4b84-b0b7-4caeef26fd6f"};
|
||||||
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
const auto& refind_config_text = gucc::bootloader::gen_refind_config(kernel_params);
|
||||||
assert(refind_config_text == REFIND_CONFIG_LUKS_SUBVOL_TEST);
|
REQUIRE(refind_config_text == REFIND_CONFIG_LUKS_SUBVOL_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
#include "gucc/bootloader.hpp"
|
#include "gucc/bootloader.hpp"
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/logger.hpp"
|
#include "gucc/logger.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@ -29,7 +29,8 @@ inline auto filtered_res(std::string_view content) noexcept -> std::string {
|
|||||||
return result + '\n';
|
return result + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("refind extra kern strings test")
|
||||||
|
{
|
||||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg&) {
|
||||||
// noop
|
// noop
|
||||||
});
|
});
|
||||||
@ -40,11 +41,14 @@ int main() {
|
|||||||
// prepare test data
|
// prepare test data
|
||||||
static constexpr std::string_view file_testpath{"/tmp/test-extrakernverstr-refind.conf"};
|
static constexpr std::string_view file_testpath{"/tmp/test-extrakernverstr-refind.conf"};
|
||||||
static constexpr std::string_view file_sample_path{GUCC_TEST_DIR "/files/refind.conf-sample"};
|
static constexpr std::string_view file_sample_path{GUCC_TEST_DIR "/files/refind.conf-sample"};
|
||||||
|
|
||||||
|
const std::vector<std::string> extra_kernel_strings{"linux-lts", "linux", "linux-zen"};
|
||||||
|
|
||||||
|
SECTION("test valid extkernstr with valid file")
|
||||||
|
{
|
||||||
fs::copy_file(file_sample_path, file_testpath, fs::copy_options::overwrite_existing);
|
fs::copy_file(file_sample_path, file_testpath, fs::copy_options::overwrite_existing);
|
||||||
|
|
||||||
// test valid extkernstr with valid file.
|
REQUIRE(gucc::bootloader::refind_write_extra_kern_strings(file_testpath, extra_kernel_strings));
|
||||||
const std::vector<std::string> extra_kernel_strings{"linux-lts", "linux", "linux-zen"};
|
|
||||||
assert(gucc::bootloader::refind_write_extra_kern_strings(file_testpath, extra_kernel_strings));
|
|
||||||
|
|
||||||
auto refind_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
auto refind_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
||||||
auto filtered_content = filtered_res(refind_conf_content);
|
auto filtered_content = filtered_res(refind_conf_content);
|
||||||
@ -52,28 +56,27 @@ int main() {
|
|||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(file_testpath);
|
fs::remove(file_testpath);
|
||||||
|
|
||||||
assert(filtered_content == REFIND_CONF_TEST);
|
REQUIRE_EQ(filtered_content, REFIND_CONF_TEST);
|
||||||
|
}
|
||||||
// test empty kernel strings with valid file.
|
SECTION("test empty kernel strings with valid file")
|
||||||
|
{
|
||||||
fs::copy_file(file_sample_path, file_testpath, fs::copy_options::overwrite_existing);
|
fs::copy_file(file_sample_path, file_testpath, fs::copy_options::overwrite_existing);
|
||||||
assert(!gucc::bootloader::refind_write_extra_kern_strings(file_testpath, {}));
|
|
||||||
|
REQUIRE(!gucc::bootloader::refind_write_extra_kern_strings(file_testpath, {}));
|
||||||
auto sample_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
auto sample_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
||||||
refind_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
auto refind_conf_content = gucc::file_utils::read_whole_file(file_testpath);
|
||||||
assert(refind_conf_content == sample_conf_content);
|
REQUIRE_EQ(refind_conf_content, sample_conf_content);
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(file_testpath);
|
fs::remove(file_testpath);
|
||||||
|
}
|
||||||
|
SECTION("test empty file")
|
||||||
|
{
|
||||||
|
REQUIRE(gucc::file_utils::create_file_for_overwrite(file_testpath, ""));
|
||||||
|
|
||||||
// test empty file
|
REQUIRE(!gucc::bootloader::refind_write_extra_kern_strings(file_testpath, extra_kernel_strings));
|
||||||
std::ofstream test_file{file_testpath.data()};
|
|
||||||
assert(test_file.is_open());
|
|
||||||
|
|
||||||
// setup file
|
|
||||||
test_file << "";
|
|
||||||
test_file.close();
|
|
||||||
|
|
||||||
assert(!gucc::bootloader::refind_write_extra_kern_strings(file_testpath, extra_kernel_strings));
|
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
fs::remove(file_testpath);
|
fs::remove(file_testpath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
gucc/tests/unit.cpp
Normal file
2
gucc/tests/unit.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest_compatibility.h"
|
@ -67,6 +67,7 @@ ranges = dependency('range-v3', version : ['>=0.11.0'], fallback : ['range-v3',
|
|||||||
tomlplusplus = dependency('tomlplusplus', version : ['>=3.4.0'], fallback : ['tomlplusplus', 'tomlplusplus_dep'], default_options: ['compile_library=false'])
|
tomlplusplus = dependency('tomlplusplus', version : ['>=3.4.0'], fallback : ['tomlplusplus', 'tomlplusplus_dep'], default_options: ['compile_library=false'])
|
||||||
#glibmm = dependency('glibmm-2.4', version : ['>=2.56.0'])
|
#glibmm = dependency('glibmm-2.4', version : ['>=2.56.0'])
|
||||||
cpr = dependency('cpr', version : ['>=1.10.0'], fallback : ['cpr', 'cpr_dep'])
|
cpr = dependency('cpr', version : ['>=1.10.0'], fallback : ['cpr', 'cpr_dep'])
|
||||||
|
doctest = dependency('doctest', version : ['>=2.4.11'], fallback : ['doctest', 'doctest_dep'])
|
||||||
|
|
||||||
src_files = files(
|
src_files = files(
|
||||||
'src/view.hpp',
|
'src/view.hpp',
|
||||||
|
12
subprojects/doctest.wrap
Normal file
12
subprojects/doctest.wrap
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[wrap-file]
|
||||||
|
directory = doctest-2.4.11
|
||||||
|
source_url = https://github.com/doctest/doctest/archive/refs/tags/v2.4.11.tar.gz
|
||||||
|
source_filename = doctest-2.4.11.tar.gz
|
||||||
|
source_hash = 632ed2c05a7f53fa961381497bf8069093f0d6628c5f26286161fbd32a560186
|
||||||
|
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/doctest_2.4.11-1/doctest-2.4.11.tar.gz
|
||||||
|
wrapdb_version = 2.4.11-1
|
||||||
|
|
||||||
|
diff_files = doctest/0001-fix-include-doctest.patch
|
||||||
|
|
||||||
|
[provide]
|
||||||
|
dependency_names = doctest
|
@ -0,0 +1,12 @@
|
|||||||
|
diff --git a/meson.build b/meson.build
|
||||||
|
index 585dd55..f2f193b 100644
|
||||||
|
--- a/meson.build
|
||||||
|
+++ b/meson.build
|
||||||
|
@@ -1,6 +1,6 @@
|
||||||
|
project('doctest', ['cpp'], version: '2.4.11')
|
||||||
|
|
||||||
|
-doctest_dep = declare_dependency(include_directories: include_directories('doctest'))
|
||||||
|
+doctest_dep = declare_dependency(include_directories: include_directories('.'))
|
||||||
|
|
||||||
|
if meson.version().version_compare('>=0.54.0')
|
||||||
|
meson.override_dependency('doctest', doctest_dep)
|
Loading…
Reference in New Issue
Block a user