tests: add tests for flake services manager

This commit is contained in:
dettlaff 2024-05-25 01:13:46 +04:00 committed by Inex Code
parent 7d0cc5e630
commit 0593c8cc8e
4 changed files with 89 additions and 1 deletions

View file

@ -19,7 +19,7 @@ class FlakeServiceManager:
def _extract_services( def _extract_services(
self, input_string: str self, input_string: str
) -> Tuple[Optional[str], Optional[str]]: ) -> Tuple[Optional[str], Optional[str]]:
pattern = r"inputs\.(\w+)\.url\s*=\s*(\S+);" pattern = r"inputs\.([\w-]+)\.url\s*=\s*([\S]+);"
match = re.search(pattern, input_string) match = re.search(pattern, input_string)
if match: if match:

View file

@ -0,0 +1,72 @@
import pytest
from selfprivacy_api.services.flake_service_manager import FlakeServiceManager
@pytest.fixture
def some_services_flake_mock(mocker, datadir):
mocker.patch(
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
new=datadir / "some_services.nix",
)
@pytest.fixture
def no_services_flake_mock(mocker, datadir):
mocker.patch(
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
new=datadir / "no_services.nix",
)
def test_read_services_list(some_services_flake_mock):
with FlakeServiceManager() as manager:
services = {
"bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden",
"gitea": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea",
"jitsi-meet": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet",
}
assert manager.services == services
def test_change_services_list(some_services_flake_mock):
services = {
"bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden",
"gitea": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea",
"jitsi-meet": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet",
"nextcloud": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/nextcloud",
"ocserv": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/ocserv",
"pleroma": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/pleroma",
"simple-nixos-mailserver": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/simple-nixos-mailserver",
}
with FlakeServiceManager() as manager:
manager.services = services
with FlakeServiceManager() as manager:
assert manager.services == services
def test_read_empty_services_list(no_services_flake_mock):
with FlakeServiceManager() as manager:
services = {}
assert manager.services == services
def test_change_empty_services_list(no_services_flake_mock):
services = {
"bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden",
"gitea": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea",
"jitsi-meet": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet",
"nextcloud": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/nextcloud",
"ocserv": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/ocserv",
"pleroma": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/pleroma",
"simple-nixos-mailserver": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/simple-nixos-mailserver",
}
with FlakeServiceManager() as manager:
manager.services = services
with FlakeServiceManager() as manager:
assert manager.services == services

View file

@ -0,0 +1,4 @@
{
description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";
outputs = _: { };
}

View file

@ -0,0 +1,12 @@
{
description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";
inputs.bitwarden.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden;
inputs.gitea.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea;
inputs.jitsi-meet.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet;
outputs = _: { };
}