Skip to content

Commit 43e7203

Browse files
committed
test: adding shortened git commit hash tests
1 parent 187ecf8 commit 43e7203

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: A shortened Git commit hash can be provided as an argument to indicate where to start taking the range of commits from till HEAD, instead of a full Git commit hash.
2+
3+
4+
Scenario Outline: A shortened and full Git commit hash can be used interchangeably.
5+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
6+
When the argument --from-commit-hash is provided as "<from_commit_hash>".
7+
Then the linting passes.
8+
Given the arguments are reset.
9+
When the argument --from-commit-hash is provided as "<from_commit_hash>".
10+
Then the linting passes.
11+
12+
13+
Examples:
14+
| repository | checkout_commit | from_commit_hash | shortened_from_commit_hash |
15+
| https://github.com/danielduarte/diffparse.git | df6be23b79af66d3684fb27719020e1ce587f4b8 | 4f6bf53139fe66f61bd05893bcc9de6e96400c5c | 4f6bf53 |
16+
17+
18+
Scenario Outline: The shortened Git commit hash has no matches, so an error is returned.
19+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
20+
When the argument --from-commit-hash is provided as "<from_shortened_commit_hash>".
21+
Then their is a could not find shortened commit hash "<from_shortened_commit_hash>" error.
22+
23+
24+
Examples:
25+
| repository | checkout_commit | from_shortened_commit_hash |
26+
| https://gitlab.com/dmfay/massive-js.git | 482c364acf5505b81c55245fac0472890d351662 | 3f235ee |
27+
28+
29+
Scenario Outline: The shortened Git commit hash is ambiguous as multiple commit hashes match it, so an error is returned.
30+
Given the repository "<repository>" is cloned and checked out at the commit "<checkout_commit>".
31+
When the argument --from-commit-hash is provided as "<from_shortened_commit_hash>".
32+
Then their is a ambiguous shortened commit hash "<from_shortened_commit_hash>" error.
33+
34+
35+
Examples:
36+
| repository | checkout_commit | from_shortened_commit_hash |
37+
| https://github.com/yargs/yargs.git | 089417550ef5a5b8ce3578dd2a989191300b64cd | 3f6 |

conventional_commits_linter/end-to-end-tests/features/steps/given.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from utilities import execute_command
66

77

8+
@given('the arguments are reset.')
9+
def reset_arguments(context):
10+
context.arguments = ""
11+
12+
813
@given('the context and environment are reset.')
914
def reset_context(context):
1015
context.behave_directory = os.getcwd()
@@ -13,7 +18,7 @@ def reset_context(context):
1318
context.pre_command = ""
1419
context.conventional_commits_linter_path = context.behave_directory + \
1520
"/../../target/debug/conventional_commits_linter"
16-
context.arguments = ""
21+
reset_arguments(context)
1722

1823
if "GIT_DIR" in os.environ:
1924
del os.environ["GIT_DIR"]

conventional_commits_linter/end-to-end-tests/features/steps/then.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from behave import *
23

34
from utilities import is_json, execute_conventional_commits_linter
@@ -106,3 +107,37 @@ def then_standard_output_not_valid_json(context):
106107
@then('standard output is valid JSON.')
107108
def then_standard_output_valid_json(context):
108109
assert is_json(context.stdout)
110+
111+
112+
@then(
113+
'their is a could not find shortened commit hash "{shortened_commit_hash}" error.')
114+
def then_could_not_find_shortened_commit_hash_error(
115+
context, shortened_commit_hash):
116+
# Given
117+
could_not_find_shortened_commit_hash_error = " ERROR conventional_commits_linter_lib::commits > No commit hashes start with the provided short commit hash \"" + \
118+
shortened_commit_hash + "\".\n"
119+
120+
# When/Then
121+
then_linting_fails(context)
122+
123+
# Then
124+
assert context.stderr == could_not_find_shortened_commit_hash_error
125+
126+
127+
@then(
128+
'their is a ambiguous shortened commit hash "{shortened_commit_hash}" error.')
129+
def then_ambiguous_shortened_commit_hash_error(context, shortened_commit_hash):
130+
# Given
131+
ambiguous_shortened_commit_hash_error = re.compile(
132+
'^ ERROR conventional_commits_linter_lib::commits > Ambiguous short commit hash, the commit hashes [[](' +
133+
shortened_commit_hash +
134+
'[a-f0-9]*(, )?)*[]] all start with the provided short commit hash "' +
135+
shortened_commit_hash +
136+
'".\n$')
137+
138+
# When/Then
139+
then_linting_fails(context)
140+
141+
# Then
142+
assert ambiguous_shortened_commit_hash_error.match(
143+
context.stderr) is not None

0 commit comments

Comments
 (0)