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.
test(daemon): cover domain layer with unit tests
Covers (most of) the domain layer with unit tests, also fixes some bugs found along the way.
- Loading branch information
1 parent
b592fcb
commit f873127
Showing
31 changed files
with
979 additions
and
4 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
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,24 @@ | ||
name: Run CTest | ||
on: workflow_call | ||
|
||
jobs: | ||
run-ctest: | ||
name: Run CTest | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Download Docker image from artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: bxt-development-image | ||
path: distfiles | ||
- name: Load Docker image | ||
run: docker load -i distfiles/bxt-development.tar | ||
- uses: addnab/docker-run-action@v3 | ||
with: | ||
image: anydistro/bxt-development:latest | ||
options: -v ${{ github.workspace }}:/src | ||
run: | | ||
cd /src/build | ||
ctest --output-on-failure |
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
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
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
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
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
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
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
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
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
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,53 @@ | ||
################################################################################ | ||
# Test Configuration | ||
################################################################################ | ||
|
||
find_package(Catch2 REQUIRED) | ||
|
||
################################################################################ | ||
# Test Sources | ||
################################################################################ | ||
|
||
file(GLOB_RECURSE TEST_SOURCES "src/unit/*/**.cpp") | ||
file(GLOB_RECURSE BXT_SOURCES "../*/**.cpp") | ||
|
||
################################################################################ | ||
# Test Executable | ||
################################################################################ | ||
|
||
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 | ||
) | ||
|
||
set_target_properties(daemon_tests PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests | ||
) | ||
|
||
get_target_property(TESTS_RUNTIME_OUTPUT_DIRECTORY daemon_tests RUNTIME_OUTPUT_DIRECTORY) | ||
|
||
message("Tests will be run from ${TESTS_RUNTIME_OUTPUT_DIRECTORY}") | ||
|
||
################################################################################ | ||
# Test Data | ||
################################################################################ | ||
|
||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${TESTS_RUNTIME_OUTPUT_DIRECTORY}) | ||
|
||
################################################################################ | ||
# CTest Integration | ||
################################################################################ | ||
include(Catch) | ||
|
||
catch_discover_tests(daemon_tests WORKING_DIRECTORY ${TESTS_RUNTIME_OUTPUT_DIRECTORY}) |
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
daemon/tests/src/unit/core/domain/entities/PackageTest.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,27 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <[email protected]> | ||
* 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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
daemon/tests/src/unit/core/domain/entities/SectionTest.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,49 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <[email protected]> | ||
* 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 <[email protected]> | ||
* 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()); | ||
} | ||
} |
Oops, something went wrong.