add file change check to copy_env_files, add test cases for copy_env_files
This commit is contained in:
parent
5102cf2d91
commit
8e926d4e64
3 changed files with 159 additions and 6 deletions
|
|
@ -38,7 +38,7 @@ class Coordinator:
|
|||
def prepare_tests(self) -> None:
|
||||
logger.info("calling prepare_tests()")
|
||||
self.DIR.create_all_dirs()
|
||||
self.ENV.copy_env_files(self.DIR)
|
||||
self.ENV.copy_env_files(self.ENV.env_files, self.DIR)
|
||||
self.load_test_credentials(self.DIR)
|
||||
|
||||
def run_tests(self) -> None:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ from typing import TYPE_CHECKING, NamedTuple
|
|||
|
||||
from dotenv import dotenv_values
|
||||
|
||||
from pytest_abra.utils import files_are_same
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pytest_abra import DirManager, Runner
|
||||
|
||||
|
|
@ -93,11 +95,25 @@ class EnvManager:
|
|||
"Could not resolve test order. This is possibly due to a circular dependency (a on b, b on c, c on a)"
|
||||
)
|
||||
|
||||
def copy_env_files(self, DIR: "DirManager") -> None:
|
||||
"""Copies all env files to STATES/env_files. Files will be renamed to
|
||||
<index>-<env_type>-<original_name>
|
||||
00-authentik-login.test.dev.local-it.cloud.env"""
|
||||
@staticmethod
|
||||
def copy_env_files(env_files: list[EnvFile], DIR: "DirManager") -> None:
|
||||
"""Copies all env files to STATES/env_files.
|
||||
|
||||
for index, env_file in enumerate(self.env_files):
|
||||
Files will be renamed to <index>-<env_type>-<original_name>. Example:
|
||||
00-authentik-login.test.dev.local-it.cloud.env
|
||||
|
||||
Does nothing when called twice with same env_files. Throws an AssertionError if either
|
||||
contents or filenames of env_files have changed (probably test rerun with different input)"""
|
||||
|
||||
dir_was_not_empty = len(list(DIR.ENV_FILES.iterdir())) > 0
|
||||
|
||||
for index, env_file in enumerate(env_files):
|
||||
file_name = "-".join([str(index).zfill(2), env_file.env_type, env_file.env_path.name])
|
||||
if dir_was_not_empty:
|
||||
# check that the copied env files have not changed
|
||||
present_files = [f.name for f in DIR.ENV_FILES.iterdir()]
|
||||
assert (
|
||||
file_name in present_files and files_are_same(env_file.env_path, DIR.ENV_FILES / file_name)
|
||||
), "It appears that you are resuming a test while the input env files have changed. Start a new test instead"
|
||||
|
||||
shutil.copy(env_file.env_path, DIR.ENV_FILES / file_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue