mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 04:51:27 +00:00
tests: add tests for flake services manager
This commit is contained in:
parent
7d0cc5e630
commit
0593c8cc8e
|
@ -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:
|
||||||
|
|
72
tests/test_flake_services_manager.py
Normal file
72
tests/test_flake_services_manager.py
Normal 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
|
4
tests/test_flake_services_manager/no_services.nix
Normal file
4
tests/test_flake_services_manager/no_services.nix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";
|
||||||
|
outputs = _: { };
|
||||||
|
}
|
12
tests/test_flake_services_manager/some_services.nix
Normal file
12
tests/test_flake_services_manager/some_services.nix
Normal 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 = _: { };
|
||||||
|
}
|
Loading…
Reference in a new issue