From 18e919d5e71844cdec12daaa585954428d50c10a Mon Sep 17 00:00:00 2001 From: Kalibh Halford Date: Thu, 14 Nov 2024 12:06:34 +0000 Subject: [PATCH] TEST: Add tests for skipped case --- src/main.py | 11 +++++------ tests/test_main.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main.py b/src/main.py index d105f7b..34cf5f4 100644 --- a/src/main.py +++ b/src/main.py @@ -5,7 +5,7 @@ from comparison import CompareAppVersion, CompareComposeVersion -def main(): +def main() -> bool: """ The entry point function for the action. Here we get environment variables then set environment variables when finished. @@ -20,14 +20,12 @@ def main(): labels = os.environ.get("INPUT_LABELS") if any(label in labels for label in ["documentation", "workflow"]): - return - + return False + CompareAppVersion().run(main_path / app_path, branch_path / app_path) if compose_path: compose_path = Path(compose_path) - CompareComposeVersion().run( - branch_path / app_path, branch_path / compose_path - ) + CompareComposeVersion().run(branch_path / app_path, branch_path / compose_path) github_env = os.getenv("GITHUB_ENV") with open(github_env, "a", encoding="utf-8") as env: @@ -36,6 +34,7 @@ def main(): if compose_path: env.write("compose_updated=true") env.write(f"release_tag={release_version}") + return True if __name__ == "__main__": diff --git a/tests/test_main.py b/tests/test_main.py index c8317ce..810f25a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -18,7 +18,7 @@ def test_main(mock_os, mock_compare_app, mock_compare_compose): ] with patch("builtins.open", mock_open(read_data="1.0.0")): - main() + res = main() mock_os.environ.get.assert_any_call("INPUT_LABELS") mock_os.environ.get.assert_any_call("INPUT_APP_VERSION_PATH") mock_os.environ.get.assert_any_call("INPUT_DOCKER_COMPOSE_PATH") @@ -31,3 +31,18 @@ def test_main(mock_os, mock_compare_app, mock_compare_compose): mock_compare_compose.return_value.run.assert_called_once_with( mock_branch_path / "app", mock_branch_path / "compose" ) + assert res + + +@patch("main.os") +def test_main_skip(mock_os): + """Test the main method skips the comparison methods.""" + mock_os.environ.get.side_effect = [ + Path("app"), + Path("compose"), + Path("workspace"), + ["workflow", "documentation"], + ] + with patch("builtins.open", mock_open(read_data="1.0.0")): + res = main() + assert not res