Skip to content

Commit 8480c68

Browse files
committed
Add Tests
1 parent 4f8f3ad commit 8480c68

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

tests/git-auto-commit.bats

+52-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setup() {
2121
export FAKE_DEFAULT_BRANCH=$(git config init.defaultBranch)
2222

2323
# Set default INPUT variables used by the GitHub Action
24-
export INPUT_GIT_TAG_ONLY=false
24+
export INPUT_CREATE_GIT_TAG_ONLY=false
2525
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
2626
export INPUT_COMMIT_MESSAGE="Commit Message"
2727
export INPUT_BRANCH="${FAKE_DEFAULT_BRANCH}"
@@ -1126,3 +1126,54 @@ END
11261126
assert_failure;
11271127
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
11281128
}
1129+
1130+
@test "it creates a tag if create_git_tag_only is set to true and a message has been supplied" {
1131+
INPUT_CREATE_GIT_TAG_ONLY=true
1132+
INPUT_TAGGING_MESSAGE=v1.0.0
1133+
1134+
run git_auto_commit
1135+
1136+
assert_success
1137+
1138+
assert_line "::debug::Create git tag only"
1139+
1140+
assert_line "::debug::Create tag v1.0.0"
1141+
refute_line "No tagging message supplied. No tag will be added."
1142+
1143+
assert_line "::debug::Apply push options "
1144+
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
1145+
1146+
run cat_github_output
1147+
assert_line "create_git_tag_only=true"
1148+
refute_line "changes_detected=false"
1149+
refute_line -e "commit_hash=[0-9a-f]{40}$"
1150+
1151+
# Assert a tag v1.0.0 has been created
1152+
run git tag
1153+
assert_output v1.0.0
1154+
1155+
run git ls-remote --tags --refs
1156+
assert_output --partial refs/tags/v1.0.0
1157+
}
1158+
1159+
@test "it output no tagging message supplied if no tagging message is set but create_git_tag_only is set to true" {
1160+
INPUT_CREATE_GIT_TAG_ONLY=true
1161+
INPUT_TAGGING_MESSAGE=""
1162+
1163+
run git_auto_commit
1164+
1165+
assert_success
1166+
1167+
assert_line "INPUT_TAGGING_MESSAGE: "
1168+
assert_line "No tagging message supplied. No tag will be added."
1169+
assert_line "::debug::Create git tag only"
1170+
1171+
run cat_github_output
1172+
assert_line "create_git_tag_only=true"
1173+
refute_line "changes_detected=false"
1174+
refute_line -e "commit_hash=[0-9a-f]{40}$"
1175+
1176+
# Assert no tag has been created
1177+
run git tag
1178+
assert_output ""
1179+
}

0 commit comments

Comments
 (0)