Skip to content

Commit

Permalink
TEST: Add tests for skipped case
Browse files Browse the repository at this point in the history
  • Loading branch information
khalford committed Nov 14, 2024
1 parent b7b155f commit 18e919d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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__":
Expand Down
17 changes: 16 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

0 comments on commit 18e919d

Please sign in to comment.