Skip to content

Commit aa07920

Browse files
author
Sven Siegmund
committed
refactor(test): add error text if versions are different
1 parent 85a47a3 commit aa07920

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/ci_starter/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING, Any, TextIO
55

66
from ruamel.yaml import YAML as Yaml
7+
from semver.version import Version
78

89
from .action import Action
910
from .step import Step
@@ -83,3 +84,11 @@ def update_step_data(data: Mapping[str, Any], action: Action) -> dict[str, Any]:
8384
if step.uses.name == action.name:
8485
step.uses = action
8586
return data
87+
88+
89+
def compare(actual: Version, expected: Version) -> str:
90+
if actual.compare(expected) == 1:
91+
return "newer"
92+
elif actual.compare(expected) == -1:
93+
return "older"
94+
return "same"

tests/e2e/test_update_actions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ci_starter.action import Action
88
from ci_starter.cli import cli
99
from ci_starter.constants import GITHUB_WORKFLOWS_DIR
10-
from ci_starter.utils import get_actions
10+
from ci_starter.utils import compare, get_actions
1111
from tests.e2e.constants import SUCCESSFUL_RETURN_CODE
1212

1313

@@ -68,10 +68,13 @@ def test_update_action(cli_runner: CliRunner, test_project_path_str, step_parser
6868
for file in workflows:
6969
data = step_parser.load(file)
7070
for action in get_actions(data):
71-
actual_commit = action.commit
7271
actual_version = action.version
73-
expected_commit = expected_actions[action.name].commit
72+
actual_commit = action.commit
7473
expected_version = expected_actions[action.name].version
74+
expected_commit = expected_actions[action.name].commit
7575

76+
compare_result = compare(actual_version, expected_version)
77+
assert actual_version == expected_version, (
78+
f"actual version is {compare_result} than the expected version"
79+
)
7680
assert actual_commit == expected_commit
77-
assert actual_version == expected_version

0 commit comments

Comments
 (0)