* add full integration test of cli / pytest_abra with all tests

* save path of runner_*.py in runner subclass to improve test discovery -> allows for same test name in two different runners

* reorganize output dir names

* use URL fixture everywhere

* rework coordinator interface

* add --session_id to cli args

* add log results table

* plenty of refactoring

* add assert messages

* add plenty of tests

* add /docs dir with plenty of documentation

* fix authentik setup

* add authentik cleanup, remove test user

* add random test user credential generation and integrate into test routine. random creds are saved to STATES

Reviewed-on: local-it-infrastructure/e2e_tests#16
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-12-14 14:03:58 +01:00 committed by dan
parent 016b88a68d
commit 2dd765a974
36 changed files with 1145 additions and 432 deletions

137
tests/test_env_manager.py Normal file
View file

@ -0,0 +1,137 @@
import shutil
from pathlib import Path
import pytest
from pytest_abra.dir_manager import DirManager
from pytest_abra.env_manager import EnvManager
from pytest_abra.utils import files_are_same
ENV_PATHS = [
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
]
@pytest.fixture
def tmp_output(tmp_path_factory: pytest.TempPathFactory) -> Path:
return tmp_path_factory.mktemp("output")
@pytest.fixture
def tmp_recipes(tmp_path_factory: pytest.TempPathFactory) -> Path:
return tmp_path_factory.mktemp("recipes")
def test_copy_env_files(tmp_output: Path, tmp_recipes: Path):
# create dirs in output
DIR = DirManager(output_dir=tmp_output, session_id="abc", recipes_dir=tmp_recipes)
DIR.create_all_dirs()
# confirm dir is empty
assert len(list(DIR.ENV_FILES.iterdir())) == 0
# copy env files
env_files = EnvManager._get_env_files(ENV_PATHS)
EnvManager.copy_env_files(env_files, DIR)
# check that each env file is present in DIR.ENV_FILES with correct contents
assert len(list(DIR.ENV_FILES.iterdir())) == len(env_files)
for index, env_path in enumerate(ENV_PATHS):
matching_files = [f for f in DIR.ENV_FILES.iterdir() if index == int(f.name.split("-")[0])]
assert len(matching_files) == 1
assert files_are_same(env_path, matching_files[0])
def test_copy_env_files_twice(tmp_output: Path, tmp_recipes: Path):
"""Copy the same env files twice"""
# create dirs in output
DIR = DirManager(output_dir=tmp_output, session_id="abc", recipes_dir=tmp_recipes)
DIR.create_all_dirs()
# confirm dir is empty
assert len(list(DIR.ENV_FILES.iterdir())) == 0
# copy env files
env_files = EnvManager._get_env_files(ENV_PATHS)
EnvManager.copy_env_files(env_files, DIR)
# check that each env file is present in DIR.ENV_FILES with correct contents
assert len(list(DIR.ENV_FILES.iterdir())) == len(env_files)
# copy env files again
EnvManager.copy_env_files(env_files, DIR)
for index, env_path in enumerate(ENV_PATHS):
matching_files = [f for f in DIR.ENV_FILES.iterdir() if index == int(f.name.split("-")[0])]
assert len(matching_files) == 1
assert files_are_same(env_path, matching_files[0])
def test_copy_env_files_twice_with_content_change(tmp_output: Path, tmp_recipes: Path, tmp_path: Path):
# copy env files to tmp_path
assert len(list(tmp_path.iterdir())) == 0
for f in ENV_PATHS:
shutil.copy(f, tmp_path / f.name)
ENV_PATHS_NEW = list(tmp_path.iterdir())
assert len(ENV_PATHS_NEW) > 0
# create dirs in output
DIR = DirManager(output_dir=tmp_output, session_id="abc", recipes_dir=tmp_recipes)
DIR.create_all_dirs()
# confirm dir is empty
assert len(list(DIR.ENV_FILES.iterdir())) == 0
# copy env files from tmp_path to tmp_output
env_files = EnvManager._get_env_files(ENV_PATHS_NEW)
EnvManager.copy_env_files(env_files, DIR)
# check that each env file is present in DIR.ENV_FILES with correct contents
assert len(list(DIR.ENV_FILES.iterdir())) == len(env_files)
# change content of one env_file in tmp_path
file_path = next(tmp_path.iterdir())
with open(file_path, "w") as file:
file.write("This is the new content")
# copy env files again
with pytest.raises(AssertionError) as excinfo:
EnvManager.copy_env_files(env_files, DIR)
assert "input env files have changed" in str(excinfo.value)
def test_copy_env_files_twice_with_name_change(tmp_output: Path, tmp_recipes: Path, tmp_path: Path):
# copy env files to tmp_path
assert len(list(tmp_path.iterdir())) == 0
for f in ENV_PATHS:
shutil.copy(f, tmp_path / f.name)
ENV_PATHS_NEW = list(tmp_path.iterdir())
assert len(ENV_PATHS_NEW) > 0
# create dirs in output
DIR = DirManager(output_dir=tmp_output, session_id="abc", recipes_dir=tmp_recipes)
DIR.create_all_dirs()
# confirm dir is empty
assert len(list(DIR.ENV_FILES.iterdir())) == 0
# copy env files from tmp_path to tmp_output
env_files = EnvManager._get_env_files(ENV_PATHS_NEW)
EnvManager.copy_env_files(env_files, DIR)
# check that each env file is present in DIR.ENV_FILES with correct contents
assert len(list(DIR.ENV_FILES.iterdir())) == len(env_files)
# change name of one env_file in tmp_path
file_path = next(tmp_path.iterdir())
file_path.rename(file_path.parent / (file_path.stem + "-other" + file_path.suffix))
# copy env files from tmp_path to tmp_output again
with pytest.raises(AssertionError) as excinfo:
env_files = EnvManager._get_env_files(list(tmp_path.iterdir()))
EnvManager.copy_env_files(env_files, DIR)
assert "input env files have changed" in str(excinfo.value)