forked from anydistro/bxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b592fcb
commit b59ff3b
Showing
24 changed files
with
508 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
find_package(Catch2 REQUIRED) | ||
|
||
file(GLOB_RECURSE TEST_SOURCES "*.cpp") | ||
file(GLOB_RECURSE BXT_SOURCES "../*/**.cpp") | ||
|
||
|
||
add_executable(daemon_tests | ||
${TEST_SOURCES} ${BXT_SOURCES} | ||
) | ||
|
||
target_link_libraries(daemon_tests PRIVATE | ||
Catch2::Catch2WithMain | ||
deps | ||
reflectcpp | ||
Dexode::EventBus | ||
) | ||
|
||
target_include_directories(daemon_tests PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/../ | ||
${lmdbxx_SOURCE_DIR}/include | ||
) | ||
|
||
|
||
include(CTest) | ||
include(Catch) | ||
|
||
catch_discover_tests(daemon_tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/entities/Package.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("Package", "[core][domain][entities]") { | ||
SECTION("Parse file name") { | ||
REQUIRE(Package::parse_file_name("package-1.0.0-1-x86_64.pkg.tar.zst").value() | ||
== "package"); | ||
REQUIRE(Package::parse_file_name("package-1.0.0-1-any.pkg.tar.zst").value() == "package"); | ||
REQUIRE(Package::parse_file_name("lib32-package-1.0.0-1-x86_64.pkg.tar.zst").value() | ||
== "lib32-package"); | ||
|
||
// Invalid cases | ||
REQUIRE(Package::parse_file_name("package.pkg.tar.zst") == std::nullopt); | ||
REQUIRE(Package::parse_file_name("1.0.0-1-x86_64.pkg.tar.zst") == std::nullopt); | ||
REQUIRE(Package::parse_file_name("package-") == std::nullopt); | ||
REQUIRE(Package::parse_file_name("package-1.0.0-1.pkg.tar.zst") == std::nullopt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/entities/Section.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("Section entity", "[core][domain][entities]") { | ||
SECTION("Construction and getters") { | ||
Section section(Name("stable"), Name("core"), Name("x86_64")); | ||
|
||
REQUIRE(section.branch() == Name("stable")); | ||
REQUIRE(section.repository() == Name("core")); | ||
REQUIRE(section.architecture() == Name("x86_64")); | ||
} | ||
|
||
SECTION("Setters") { | ||
Section section(Name("stable"), Name("core"), Name("x86_64")); | ||
|
||
section.set_branch(Name("testing")); | ||
REQUIRE(section.branch() == Name("testing")); | ||
|
||
section.set_repository(Name("extra")); | ||
REQUIRE(section.repository() == Name("extra")); | ||
|
||
section.set_architecture(Name("aarch64")); | ||
REQUIRE(section.architecture() == Name("aarch64")); | ||
} | ||
|
||
SECTION("ID generation") { | ||
Section section(Name("stable"), Name("core"), Name("x86_64")); | ||
REQUIRE(section.id() == "stable/core/x86_64"); | ||
} | ||
|
||
SECTION("String representation") { | ||
Section section(Name("stable"), Name("core"), Name("x86_64")); | ||
REQUIRE(section.string() == "stable/core/x86_64"); | ||
} | ||
|
||
SECTION("to_string function") { | ||
Section section(Name("stable"), Name("core"), Name("x86_64")); | ||
REQUIRE(bxt::to_string(section) == "stable/core/x86_64"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/entities/User.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("User entity", "[core][domain][entities]") { | ||
SECTION("Construction and getters") { | ||
User user(Name("testuser"), "password123"); | ||
|
||
REQUIRE(user.name() == Name("testuser")); | ||
REQUIRE(user.password() == "password123"); | ||
REQUIRE(user.permissions().empty()); | ||
} | ||
|
||
SECTION("Setters") { | ||
User user(Name("testuser"), "password123"); | ||
|
||
user.set_name("newuser"); | ||
REQUIRE(user.name() == Name("newuser")); | ||
|
||
user.set_password("newpassword"); | ||
REQUIRE(user.password() == "newpassword"); | ||
|
||
std::set<Permission> new_permissions = {Permission("read"), Permission("write")}; | ||
user.set_permissions(new_permissions); | ||
REQUIRE(user.permissions() == new_permissions); | ||
} | ||
|
||
SECTION("ID") { | ||
User user(Name("testuser"), "password123"); | ||
REQUIRE(user.id() == Name("testuser")); | ||
} | ||
|
||
SECTION("Permission checking") { | ||
User user(Name("testuser"), "password123"); | ||
std::set<Permission> permissions = {Permission("sections.*.*.*"), | ||
Permission("packages.get.stable.core.x86_64")}; | ||
user.set_permissions(permissions); | ||
|
||
REQUIRE(user.has_permission("sections.stable.core.x86_64")); | ||
REQUIRE(user.has_permission("packages.get.stable.core.x86_64")); | ||
REQUIRE_FALSE(user.has_permission("packages.snap.stable.core.x86_64")); | ||
REQUIRE_FALSE(user.has_permission("users.add")); | ||
} | ||
|
||
SECTION("Default constructor") { | ||
User default_user; | ||
REQUIRE(default_user.name() == Name("Unnamed")); | ||
REQUIRE(default_user.password().empty()); | ||
REQUIRE(default_user.permissions().empty()); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/enums/PoolLocation.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <map> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("PoolLocation enum", "[core][domain][enums]") { | ||
SECTION("to_string conversion") { | ||
REQUIRE(bxt::to_string(PoolLocation::Sync) == "sync"); | ||
REQUIRE(bxt::to_string(PoolLocation::Overlay) == "overlay"); | ||
REQUIRE(bxt::to_string(PoolLocation::Automated) == "automated"); | ||
REQUIRE_THROWS(bxt::to_string(PoolLocation::Unknown)); | ||
} | ||
|
||
SECTION("select_preferred_pool_location") { | ||
SECTION("Empty map") { | ||
std::map<PoolLocation, int> empty_map; | ||
auto result = select_preferred_pool_location(empty_map); | ||
REQUIRE_FALSE(result.has_value()); | ||
} | ||
|
||
SECTION("Single element map") { | ||
std::map<PoolLocation, int> single_map = {{PoolLocation::Sync, 1}}; | ||
auto result = select_preferred_pool_location(single_map); | ||
REQUIRE(result.has_value()); | ||
REQUIRE(*result == PoolLocation::Sync); | ||
} | ||
|
||
SECTION("Multiple elements map") { | ||
std::map<PoolLocation, int> multi_map = { | ||
{PoolLocation::Sync, 1}, {PoolLocation::Overlay, 2}, {PoolLocation::Automated, 3}}; | ||
auto result = select_preferred_pool_location(multi_map); | ||
REQUIRE(result.has_value()); | ||
REQUIRE(*result == PoolLocation::Overlay); | ||
} | ||
|
||
SECTION("Map with Unknown location") { | ||
std::map<PoolLocation, int> map_with_unknown = { | ||
{PoolLocation::Unknown, 0}, {PoolLocation::Automated, 1}, {PoolLocation::Sync, 2}}; | ||
auto result = select_preferred_pool_location(map_with_unknown); | ||
REQUIRE(result.has_value()); | ||
REQUIRE(*result == PoolLocation::Automated); | ||
} | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
62 changes: 62 additions & 0 deletions
62
daemon/tests/core/domain/services/PermissionMatcherTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/services/PermissionMatcher.h" | ||
|
||
#include "core/domain/value_objects/Permission.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("PermissionMatcher", "[core][domain][services]") { | ||
SECTION("Exact match") { | ||
Permission p1("a.b.c"); | ||
Permission p2("a.b.c"); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Wildcard match") { | ||
Permission p1("a.*.c"); | ||
Permission p2("a.b.c"); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Partial match with wildcard") { | ||
Permission p1("a.*"); | ||
Permission p2("a.b.c"); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("No match") { | ||
Permission p1("a.b.c"); | ||
Permission p2("x.y.z"); | ||
REQUIRE_FALSE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Different length, no match") { | ||
Permission p1("a.b"); | ||
Permission p2("a.b.c"); | ||
REQUIRE_FALSE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Different length with wildcard, match") { | ||
Permission p1("a.b.*"); | ||
Permission p2("a.b.c.d"); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Empty permissions") { | ||
Permission p1(""); | ||
Permission p2(""); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
|
||
SECTION("Single wildcard") { | ||
Permission p1("*"); | ||
Permission p2("a.b.c"); | ||
REQUIRE(PermissionMatcher::match(p1, p2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/value_objects/Name.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <fmt/format.h> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("Name", "[core][domain][value_objects]") { | ||
SECTION("Construction and string conversion") { | ||
Name name("TestName"); | ||
REQUIRE(static_cast<std::string>(name) == "TestName"); | ||
} | ||
|
||
SECTION("Empty name throws exception") { | ||
REQUIRE_THROWS(Name("")); | ||
} | ||
|
||
SECTION("Comparison") { | ||
Name name1("Name1"); | ||
Name name2("Name1"); | ||
Name name3("Name2"); | ||
|
||
REQUIRE(name1 == name2); | ||
REQUIRE(name1 != name3); | ||
REQUIRE(name1 < name3); | ||
REQUIRE(name3 > name1); | ||
} | ||
|
||
SECTION("Formatting") { | ||
Name name("FormatTest"); | ||
std::string formatted = fmt::format("{}", name); | ||
REQUIRE(formatted == "FormatTest"); | ||
} | ||
} |
Empty file.
65 changes: 65 additions & 0 deletions
65
daemon/tests/core/domain/value_objects/PackagePoolEntryTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <agrinev@manjaro.org> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#include "core/domain/value_objects/PackagePoolEntry.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <filesystem> | ||
|
||
using namespace bxt::Core::Domain; | ||
|
||
TEST_CASE("PackagePoolEntry", "[core][domain][value_objects]") { | ||
SECTION("Parse valid file path") { | ||
std::filesystem::path file_path = "package-1.0.0-1-x86_64.pkg.tar.zst"; | ||
auto result = PackagePoolEntry::parse_file_path(file_path, std::nullopt); | ||
REQUIRE(result.has_value()); | ||
auto entry = result.value(); | ||
REQUIRE(entry.file_path() == file_path); | ||
REQUIRE(entry.version().string() == "1.0.0-1"); | ||
} | ||
|
||
SECTION("Parse file path with signature") { | ||
std::filesystem::path file_path = "package-1.0.0-1-x86_64.pkg.tar.zst"; | ||
std::filesystem::path sig_path = "package-1.0.0-1-x86_64.pkg.tar.zst.sig"; | ||
auto result = PackagePoolEntry::parse_file_path(file_path, sig_path); | ||
REQUIRE(result.has_value()); | ||
auto entry = result.value(); | ||
REQUIRE(entry.file_path() == file_path); | ||
REQUIRE(entry.signature_path() == sig_path); | ||
} | ||
|
||
SECTION("Parse invalid file path") { | ||
std::filesystem::path file_path = "invalid-package-name"; | ||
auto result = PackagePoolEntry::parse_file_path(file_path, std::nullopt); | ||
REQUIRE_FALSE(result.has_value()); | ||
REQUIRE(result.error().error_code | ||
== PackagePoolEntry::ParsingError::ErrorCode::InvalidFilename); | ||
} | ||
|
||
SECTION("Parse file path with invalid version") { | ||
std::filesystem::path file_path = "package-invalid-version-x86_64.pkg.tar.zst"; | ||
auto result = PackagePoolEntry::parse_file_path(file_path, std::nullopt); | ||
REQUIRE_FALSE(result.has_value()); | ||
REQUIRE(result.error().error_code | ||
== PackagePoolEntry::ParsingError::ErrorCode::InvalidVersion); | ||
} | ||
|
||
SECTION("Accessors") { | ||
std::filesystem::path file_path = "package-1.0.0-1-x86_64.pkg.tar.zst"; | ||
std::filesystem::path sig_path = "package-1.0.0-1-x86_64.pkg.tar.zst.sig"; | ||
bxt::Utilities::AlpmDb::Desc desc; | ||
PackageVersion version = PackageVersion::from_string("1.0.0-1").value(); | ||
|
||
PackagePoolEntry entry(file_path, sig_path, desc, version); | ||
|
||
REQUIRE(entry.file_path() == file_path); | ||
REQUIRE(entry.signature_path() == sig_path); | ||
REQUIRE(entry.version().string() == version.string()); | ||
REQUIRE(entry.desc().desc == desc.desc); | ||
REQUIRE(entry.desc().files == desc.files); | ||
} | ||
} |
Oops, something went wrong.