From 94be2c00acc165ea56cfe64527e842b2b9ca72ef Mon Sep 17 00:00:00 2001
From: Hans Fangohr <fangohr@users.noreply.github.com>
Date: Sat, 27 May 2023 18:31:46 +0200
Subject: [PATCH] create git repo to reflect execution in production
 environment

---
 tests.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tests.py b/tests.py
index 04e1e4e..d4c9e93 100644
--- a/tests.py
+++ b/tests.py
@@ -43,6 +43,25 @@ def test_prepare_environment(tmp_path):
     # check that the test directory does not exist
     assert not script_dir.exists()
 
+    # prepare_environment expects to be executed in git repository
+    # (mpsd-software-environments). It queries the commit on which we are to
+    # log that information. For this to work, we need to execute the command
+    # within a directory tree that has a git repository at the same or high
+    # level. Let's create one:
+
+    # create directory first
+    script_dir.mkdir(parents=True)
+    # then create git repository:
+    with mod.os_chdir(str(script_dir)):
+        subprocess.run("git init .", shell=True, check=True)
+        subprocess.run("echo 'fake content' > readme.txt", shell=True, check=True)
+        subprocess.run("git add readme.txt", shell=True, check=True)
+        subprocess.run("pwd", shell=True)
+        subprocess.run(
+            'git commit -m "first commit" readme.txt', shell=True, check=True
+        )
+
+    # now call the function we want to test
     result = mod.prepare_environment(
         mpsd_release=mpsd_release_to_test, script_dir=(script_dir)
     )
-- 
GitLab