Skip to content

Commit 42a6b37

Browse files
author
Alan Christie
committed
fix: First test group dry-run
1 parent e059169 commit 42a6b37

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

src/jote/compose.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,47 @@ def delete(self) -> None:
261261
shutil.rmtree(test_path)
262262

263263
print("# Compose: Deleted")
264+
265+
@staticmethod
266+
def run_group_compose_file(compose_file: str) -> bool:
267+
"""Runs a group compose file in a detached state.
268+
The file is expected to be resident in the 'data-manager' directory."""
269+
try:
270+
# Bring the compose file up...
271+
_ = subprocess.run(
272+
[
273+
"docker-compose",
274+
"-f",
275+
os.path.join("data-manager", compose_file),
276+
"up",
277+
"-d",
278+
],
279+
capture_output=False,
280+
check=False,
281+
)
282+
except: # pylint: disable=bare-except
283+
return False
284+
285+
return True
286+
287+
@staticmethod
288+
def stop_group_compose_file(compose_file: str) -> bool:
289+
"""Runs a group compose file in a detached state.
290+
The file is expected to be ..."""
291+
try:
292+
# Bring the compose file down...
293+
_ = subprocess.run(
294+
[
295+
"docker-compose",
296+
"-f",
297+
os.path.join("data-manager", compose_file),
298+
"down",
299+
],
300+
capture_output=False,
301+
timeout=240,
302+
check=False,
303+
)
304+
except: # pylint: disable=bare-except
305+
return False
306+
307+
return True

src/jote/jote.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,22 @@ def _run_grouped_tests(
942942
# an 'ordinal', 'job name', 'job test' and the 'job' definition
943943

944944
# Start the group compose file?
945-
if index == 0 and "compose-file" in grouped_test[0]:
946-
compose_file = grouped_test[0]["compose-file"]
947-
print(
948-
f"Grouped Test =-> {jd_filename}:"
949-
f' compose-file="{compose_file}" [UP]'
945+
if (
946+
index == 0
947+
and "compose-file" in grouped_test[0]
948+
and not args.dry_run
949+
):
950+
group_compose_file = grouped_test[0]["compose-file"]
951+
assert group_compose_file
952+
g_compose_result: bool = Compose.run_group_compose_file(
953+
group_compose_file
950954
)
955+
if not g_compose_result:
956+
print("! FAILURE")
957+
print(
958+
f"! Test group compose file failed ({group_compose_file})"
959+
)
960+
break
951961

952962
# The test
953963
compose, test_result = _run_a_test(
@@ -978,11 +988,8 @@ def _run_grouped_tests(
978988

979989
# Always stop the group compose file at the end of the test group
980990
# (if there is one)
981-
if group_compose_file:
982-
print(
983-
f"Grouped Test =-> {jd_filename}:"
984-
f' compose-file="{group_compose_file}" [DOWN]'
985-
)
991+
if group_compose_file and not args.dry_run:
992+
_ = Compose.stop_group_compose_file(group_compose_file)
986993

987994
# Told to exit on first failure?
988995
if test_result == TestResult.FAILED and args.exit_on_failure:

0 commit comments

Comments
 (0)