diff --git a/t/fixtures/programs.py b/t/fixtures/programs.py index 22511487..ccd69e9b 100644 --- a/t/fixtures/programs.py +++ b/t/fixtures/programs.py @@ -1,5 +1,5 @@ import pytest -from os import getuid +from os import chown, getuid, getgid from pathlib import Path import subprocess import sys @@ -147,6 +147,14 @@ def process_pool(env, cfg, git): src = cfg.get("ngcpcfg", key_base) copy_tree(src, src, dst_pool) cfg.set("ngcpcfg", key_base, str(dst_pool)) + + # ensure we have valid user information + git.config("--local", "user.email", "pytest@example.com") + git.config("--local", "user.name", "pytest") + + # required for git versions >=2.35.2 + chown(ngcpctl_dir, getuid(), getgid()) + ex, out, err = git.add("templates") assert ex == 0 # print("{}\nstdout:\n{}stderr:{}\n".format("git add", out, err)) @@ -159,6 +167,10 @@ def process_pool(env, cfg, git): dir_path = Path(outdir).joinpath(dir[1:]) print("create empty git repository at {}".format(dir_path)) gitrepo.extract_archive(str(EMPTY_GIT), dir_path) + # ensure we have valid user information + git.config("--local", "user.email", "pytest@example.com") + git.config("--local", "user.name", "pytest") + def process_conf(env, cfg, git): base = Path(cfg.get("ngcpcfg", "NGCPCTL_MAIN")) @@ -199,15 +211,21 @@ def prepare_conf(env={}): config.set("ngcpcfg", key, str(testenv[key])) with gitrepo.in_folder(ngcpctl_dir) as git: - git.config("user.email", "fake@pytest.fake") - git.config("user.name", "pytest") + # ensure we have valid user information + git.config("--local", "user.email", "pytest@example.com") + git.config("--local", "user.name", "pytest") process_conf(testenv, config, git) # generate NGCPCFG with config values testenv["NGCPCFG"] = gen_cfg(config, ngcpctl_dir) git.add(testenv["NGCPCFG"]) + # ex, out, err = git.diff("HEAD") # print("{}\nstdout:\n{}stderr:{}\n".format("git diff", out, err)) ex, out, err = git.commit("-a", "-m", "prepare_conf done") + + # for debugging underlying problems like safe.directory situation + print("debug: git show: {}\n".format(subprocess.getoutput("git show"))) + print("{}\nstdout:\n{}stderr:{}\n".format("git commit", out, err)) assert ex == 0 return testenv, config["ngcpcfg"] @@ -296,4 +314,4 @@ def run(helper, *args, env={}): ) return result - return run \ No newline at end of file + return run diff --git a/t/test_git.py b/t/test_git.py index 293b90d1..2e17c84e 100644 --- a/t/test_git.py +++ b/t/test_git.py @@ -9,9 +9,14 @@ def test_add_file_to_default_repo(cli, gitrepo): src = "default-git-repository.tar.gz" with gitrepo.from_archive(src) as git: - # configure git user - git.config("--local", "user.email", "me@example.com") - git.config("--local", "user.name", "pytest robot") + # required for git versions >=2.35.2 + os.chown(git.root, os.getuid(), os.getgid()) + + # ensure we have valid user information + git.config("--local", "user.email", "pytest@example.com") + git.config("--local", "user.name", "pytest") + + # debug information, visible only in case of errors print("Using git {}".format(git.version)) # git status @@ -39,6 +44,9 @@ def test_add_file_to_default_repo(cli, gitrepo): def test_status_output(cli, gitrepo): # we mock an existing repository by loading it from the default archive with gitrepo.from_archive(gitrepo.default) as git: + # required for git versions >=2.35.2 + os.chown(git.root, os.getuid(), os.getgid()) + # now we work with "existing" repository with path given in git.root with gitrepo.in_folder(git.root) as git: ex, out, err = git.status() diff --git a/t/test_ngcpcfg_apply_instances.py b/t/test_ngcpcfg_apply_instances.py index a3ad5132..e7e4c9d3 100644 --- a/t/test_ngcpcfg_apply_instances.py +++ b/t/test_ngcpcfg_apply_instances.py @@ -66,8 +66,9 @@ def test_apply_instances_changes(ngcpcfg, ngcpcfgcli, tmpdir, gitrepo): ] # put expected output of build_instances with gitrepo.in_folder(base_git) as git: - git.config("user.email", "fake@pytest.fake") - git.config("user.name", "pytest") + # ensure we have valid user information + git.config("--local", "user.email", "pytest@example.com") + git.config("--local", "user.name", "pytest") for file, dir in orig: dst_path = base_path.joinpath(dir) dst_path.mkdir(parents=True, exist_ok=True)