mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2024-12-06 02:09:04 +00:00
Rewrite Tests
This commit is contained in:
parent
ac4585b8d5
commit
bee2ad60b0
@ -1,439 +0,0 @@
|
|||||||
#!/usr/bin/env bats
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
. shellmock
|
|
||||||
|
|
||||||
# Build World
|
|
||||||
export test_repository="${BATS_TEST_DIRNAME}/test_repo"
|
|
||||||
|
|
||||||
rm -rf "${test_repository}"
|
|
||||||
mkdir "${test_repository}"
|
|
||||||
touch "${test_repository}"/{a,b,c}.txt
|
|
||||||
cd "${test_repository}"
|
|
||||||
|
|
||||||
git init --quiet
|
|
||||||
git add . > /dev/null 2>&1
|
|
||||||
|
|
||||||
if [[ -z $(git config user.name) ]]; then
|
|
||||||
git config --global user.email "test@github.com"
|
|
||||||
git config --global user.name "Test Suite"
|
|
||||||
fi
|
|
||||||
|
|
||||||
git commit --quiet -m "Init Repo"
|
|
||||||
|
|
||||||
# Set default INPUT variables
|
|
||||||
export INPUT_REPOSITORY="${BATS_TEST_DIRNAME}/test_repo"
|
|
||||||
export INPUT_COMMIT_MESSAGE="Commit Message"
|
|
||||||
export INPUT_BRANCH="master"
|
|
||||||
export INPUT_COMMIT_OPTIONS=""
|
|
||||||
export INPUT_FILE_PATTERN="."
|
|
||||||
export INPUT_COMMIT_USER_NAME="Test Suite"
|
|
||||||
export INPUT_COMMIT_USER_EMAIL="test@github.com"
|
|
||||||
export INPUT_COMMIT_AUTHOR="Test Suite <test@users.noreply.github.com>"
|
|
||||||
export INPUT_TAGGING_MESSAGE=""
|
|
||||||
export INPUT_PUSH_OPTIONS=""
|
|
||||||
export INPUT_SKIP_DIRTY_CHECK=false
|
|
||||||
|
|
||||||
skipIfNot "$BATS_TEST_DESCRIPTION"
|
|
||||||
|
|
||||||
if [ -z "$TEST_FUNCTION" ]; then
|
|
||||||
shellmock_clean
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown() {
|
|
||||||
|
|
||||||
if [ -z "$TEST_FUNCTION" ]; then
|
|
||||||
shellmock_clean
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf "${test_repository}"
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@test "clean-repo-prints-nothing-to-commit-message" {
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::false" ]
|
|
||||||
[ "${lines[2]}" = "Working tree clean. Nothing to commit." ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "commit-changed-files-and-push-to-remote" {
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
|
|
||||||
[ "${lines[2]}" = "INPUT_BRANCH value: master" ]
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
|
|
||||||
[ "${lines[5]}" = "::debug::Apply commit options " ]
|
|
||||||
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
|
|
||||||
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
|
|
||||||
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
|
|
||||||
[ "${lines[9]}" = "::debug::Apply push options " ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "skip-dirty-on-clean-repo-failure" {
|
|
||||||
|
|
||||||
INPUT_SKIP_DIRTY_CHECK=true
|
|
||||||
|
|
||||||
shellmock_expect git --type exact --match "status -s ."
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type exact --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
|
|
||||||
# Failed Exit Code
|
|
||||||
[ "$status" -ne 0 ]
|
|
||||||
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
|
|
||||||
[ "${lines[2]}" = "INPUT_BRANCH value: master" ]
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
|
|
||||||
[ "${lines[5]}" = "::debug::Apply commit options " ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "git-add-file-pattern-is-applied" {
|
|
||||||
|
|
||||||
INPUT_FILE_PATTERN="*.txt *.html"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2}.php
|
|
||||||
touch "${test_repository}"/new-file-{1,2}.html
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.html M new-file-2.html" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add"
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: *.txt *.html" ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- a.txt b.txt c.txt new-file-1.html new-file-2.html" ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add a.txt b.txt c.txt new-file-1.html new-file-2.html" ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "git-commit-options-are-applied" {
|
|
||||||
|
|
||||||
INPUT_COMMIT_OPTIONS="--no-verify --signoff"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add"
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: --no-verify --signoff" ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com> --no-verify --signoff" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "commit-user-and-author-settings-are-applied" {
|
|
||||||
|
|
||||||
INPUT_COMMIT_USER_NAME="A Single Test"
|
|
||||||
INPUT_COMMIT_USER_EMAIL="single-test@github.com"
|
|
||||||
INPUT_COMMIT_AUTHOR="A Single Test <single@users.noreply.github.com>"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add"
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=A Single Test -c user.email=single-test@github.com commit -m Commit Message --author=A Single Test <single@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "can-create-tag" {
|
|
||||||
|
|
||||||
INPUT_TAGGING_MESSAGE="v1.0.0"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: v1.0.0" ]
|
|
||||||
[ "${lines[7]}" = "::debug::Create tag v1.0.0" ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com tag -a v1.0.0 -m v1.0.0" ]
|
|
||||||
[ "${capture[6]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "git-push-options-are-applied" {
|
|
||||||
|
|
||||||
INPUT_PUSH_OPTIONS="--force"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout master"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: --force" ]
|
|
||||||
[ "${lines[9]}" = "::debug::Apply push options --force" ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout master" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags --force" ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "can-checkout-different-branch" {
|
|
||||||
|
|
||||||
INPUT_BRANCH="foo"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout foo"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push --set-upstream origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
|
|
||||||
[ "${lines[2]}" = "INPUT_BRANCH value: foo" ]
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
|
|
||||||
[ "${lines[5]}" = "::debug::Apply commit options " ]
|
|
||||||
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
|
|
||||||
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
|
|
||||||
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
|
|
||||||
[ "${lines[9]}" = "::debug::Apply push options " ]
|
|
||||||
[ "${lines[10]}" = "::debug::Push commit to remote branch foo" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout foo" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:foo --tags" ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "can-work-with-empty-branch-name" {
|
|
||||||
|
|
||||||
INPUT_BRANCH=""
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
|
|
||||||
[ "${lines[2]}" = "INPUT_BRANCH value: " ]
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
|
|
||||||
[ "${lines[5]}" = "::debug::Apply commit options " ]
|
|
||||||
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
|
|
||||||
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
|
|
||||||
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
|
|
||||||
[ "${lines[9]}" = "::debug::Apply push options " ]
|
|
||||||
[ "${lines[10]}" = "::debug::git push origin" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub push origin" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "can-work-with-empty-branch-name-and-tags" {
|
|
||||||
|
|
||||||
INPUT_BRANCH=""
|
|
||||||
INPUT_TAGGING_MESSAGE="v2.0.0"
|
|
||||||
|
|
||||||
touch "${test_repository}"/new-file-{1,2,3}.txt
|
|
||||||
|
|
||||||
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
|
|
||||||
shellmock_expect git --type exact --match "fetch"
|
|
||||||
shellmock_expect git --type exact --match "checkout"
|
|
||||||
shellmock_expect git --type partial --match "add ."
|
|
||||||
shellmock_expect git --type partial --match '-c'
|
|
||||||
shellmock_expect git --type partial --match 'push origin'
|
|
||||||
|
|
||||||
run main
|
|
||||||
|
|
||||||
echo "$output"
|
|
||||||
|
|
||||||
# Success Exit Code
|
|
||||||
[ "$status" = 0 ]
|
|
||||||
|
|
||||||
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
|
|
||||||
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
|
|
||||||
[ "${lines[2]}" = "INPUT_BRANCH value: " ]
|
|
||||||
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
|
|
||||||
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
|
|
||||||
[ "${lines[5]}" = "::debug::Apply commit options " ]
|
|
||||||
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: v2.0.0" ]
|
|
||||||
[ "${lines[7]}" = "::debug::Create tag v2.0.0" ]
|
|
||||||
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
|
|
||||||
[ "${lines[9]}" = "::debug::Apply push options " ]
|
|
||||||
[ "${lines[10]}" = "::debug::git push origin --tags" ]
|
|
||||||
|
|
||||||
|
|
||||||
shellmock_verify
|
|
||||||
[ "${capture[0]}" = "git-stub status -s -- ." ]
|
|
||||||
[ "${capture[1]}" = "git-stub fetch" ]
|
|
||||||
[ "${capture[2]}" = "git-stub checkout" ]
|
|
||||||
[ "${capture[3]}" = "git-stub add ." ]
|
|
||||||
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
|
|
||||||
[ "${capture[5]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com tag -a v2.0.0 -m v2.0.0" ]
|
|
||||||
[ "${capture[6]}" = "git-stub push origin --tags" ]
|
|
||||||
|
|
||||||
}
|
|
279
tests/git-auto-commit.bats
Normal file
279
tests/git-auto-commit.bats
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load '../node_modules/bats-support/load'
|
||||||
|
load '../node_modules/bats-assert/load'
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
# Define Paths for local repository used during tests
|
||||||
|
export FAKE_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/test_fake_local_repository"
|
||||||
|
export FAKE_REMOTE="${BATS_TEST_DIRNAME}/test_fake_remote_repository"
|
||||||
|
export FAKE_TEMP_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/test_fake_temp_local_repository"
|
||||||
|
|
||||||
|
# Set default INPUT variables used by the GitHub Action
|
||||||
|
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
|
||||||
|
export INPUT_COMMIT_MESSAGE="Commit Message"
|
||||||
|
export INPUT_BRANCH="master"
|
||||||
|
export INPUT_COMMIT_OPTIONS=""
|
||||||
|
export INPUT_FILE_PATTERN="."
|
||||||
|
export INPUT_COMMIT_USER_NAME="Test Suite"
|
||||||
|
export INPUT_COMMIT_USER_EMAIL="test@github.com"
|
||||||
|
export INPUT_COMMIT_AUTHOR="Test Suite <test@users.noreply.github.com>"
|
||||||
|
export INPUT_TAGGING_MESSAGE=""
|
||||||
|
export INPUT_PUSH_OPTIONS=""
|
||||||
|
export INPUT_SKIP_DIRTY_CHECK=false
|
||||||
|
|
||||||
|
# Create and setup some fake repositories for testing
|
||||||
|
_setup_fake_remote_repository
|
||||||
|
_setup_local_repository
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
rm -rf "${FAKE_LOCAL_REPOSITORY}"
|
||||||
|
rm -rf "${FAKE_REMOTE}"
|
||||||
|
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a fake remote repository which tests can push against
|
||||||
|
_setup_fake_remote_repository() {
|
||||||
|
# Create the bare repository, which will act as our remote/origin
|
||||||
|
rm -rf "${FAKE_REMOTE}";
|
||||||
|
mkdir "${FAKE_REMOTE}";
|
||||||
|
cd "${FAKE_REMOTE}";
|
||||||
|
git init --bare;
|
||||||
|
|
||||||
|
# Clone the remote repository to a temporary location.
|
||||||
|
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||||
|
git clone "${FAKE_REMOTE}" "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||||
|
|
||||||
|
# Create some files, commit them and push them to the remote repository
|
||||||
|
touch "${FAKE_TEMP_LOCAL_REPOSITORY}"/remote-files{1,2,3}.txt
|
||||||
|
cd "${FAKE_TEMP_LOCAL_REPOSITORY}";
|
||||||
|
git add .;
|
||||||
|
git commit --quiet -m "Init Remote Repository";
|
||||||
|
git push origin master;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clone our fake remote repository and set it up for testing
|
||||||
|
_setup_local_repository() {
|
||||||
|
# Clone remote repository. In this repository we will do our testing
|
||||||
|
rm -rf "${FAKE_LOCAL_REPOSITORY}"
|
||||||
|
git clone "${FAKE_REMOTE}" "${FAKE_LOCAL_REPOSITORY}"
|
||||||
|
|
||||||
|
cd "${FAKE_LOCAL_REPOSITORY}";
|
||||||
|
|
||||||
|
# Configure Git
|
||||||
|
git config user.email "test@github.com"
|
||||||
|
git config user.name "Test Suite"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the main code related to this GitHub Action
|
||||||
|
git_auto_commit() {
|
||||||
|
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It detects changes, commits them and pushes them to the remote repository" {
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||||
|
assert_line "::set-output name=changes_detected::true"
|
||||||
|
assert_line "INPUT_BRANCH value: master"
|
||||||
|
assert_line "INPUT_FILE_PATTERN: ."
|
||||||
|
assert_line "INPUT_COMMIT_OPTIONS: "
|
||||||
|
assert_line "::debug::Apply commit options "
|
||||||
|
assert_line "INPUT_TAGGING_MESSAGE: "
|
||||||
|
assert_line "No tagging message supplied. No tag will be added."
|
||||||
|
assert_line "INPUT_PUSH_OPTIONS: "
|
||||||
|
assert_line "::debug::Apply push options "
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It prints a 'Nothing to commit' message in a clean repository" {
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||||
|
assert_line "::set-output name=changes_detected::false"
|
||||||
|
assert_line "Working tree clean. Nothing to commit."
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "If SKIP_DIRTY_CHECK is set to true on a clean repo it fails to push" {
|
||||||
|
INPUT_SKIP_DIRTY_CHECK=true
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_failure
|
||||||
|
|
||||||
|
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||||
|
assert_line "::set-output name=changes_detected::true"
|
||||||
|
|
||||||
|
assert_line "::set-output name=changes_detected::true"
|
||||||
|
assert_line "INPUT_BRANCH value: master"
|
||||||
|
assert_line "INPUT_FILE_PATTERN: ."
|
||||||
|
assert_line "INPUT_COMMIT_OPTIONS: "
|
||||||
|
assert_line "::debug::Apply commit options "
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It applies INPUT_FILE_PATTERN when creating commit" {
|
||||||
|
INPUT_FILE_PATTERN="*.txt *.html"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.html
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_FILE_PATTERN: *.txt *.html"
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
|
||||||
|
# Assert that PHP files have not been added.
|
||||||
|
run git status
|
||||||
|
assert_output --partial 'new-file-1.php'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It applies INPUT_COMMIT_OPTIONS when creating commit" {
|
||||||
|
INPUT_COMMIT_OPTIONS="--no-verify --signoff"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_COMMIT_OPTIONS: --no-verify --signoff"
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
|
||||||
|
# Assert last commit was signed off
|
||||||
|
run git log -n 1
|
||||||
|
assert_output --partial "Signed-off-by:"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It applies commit user and author settings" {
|
||||||
|
INPUT_COMMIT_USER_NAME="A Single Test"
|
||||||
|
INPUT_COMMIT_USER_EMAIL="single-test@github.com"
|
||||||
|
INPUT_COMMIT_AUTHOR="A Single Test <single@users.noreply.github.com>"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_COMMIT_USER_NAME: A Single Test";
|
||||||
|
assert_line "INPUT_COMMIT_USER_EMAIL: single-test@github.com";
|
||||||
|
assert_line "INPUT_COMMIT_AUTHOR: A Single Test <single@users.noreply.github.com>";
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
|
||||||
|
# Asser last commit was made by the defined user/author
|
||||||
|
run git log -1 --pretty=format:'%ae'
|
||||||
|
assert_output --partial "single@users.noreply.github.com"
|
||||||
|
|
||||||
|
run git log -1 --pretty=format:'%an'
|
||||||
|
assert_output --partial "A Single Test"
|
||||||
|
|
||||||
|
run git log -1 --pretty=format:'%cn'
|
||||||
|
assert_output --partial "A Single Test"
|
||||||
|
|
||||||
|
run git log -1 --pretty=format:'%ce'
|
||||||
|
assert_output --partial "single-test@github.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It creates a tag with the commit" {
|
||||||
|
INPUT_TAGGING_MESSAGE="v1.0.0"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_TAGGING_MESSAGE: v1.0.0"
|
||||||
|
assert_line "::debug::Create tag v1.0.0"
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
|
||||||
|
# Assert a tag v1.0.0 has been created
|
||||||
|
run git tag
|
||||||
|
assert_output v1.0.0
|
||||||
|
|
||||||
|
run git ls-remote --tags --refs
|
||||||
|
assert_output --partial refs/tags/v1.0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It applies INPUT_PUSH_OPTIONS when pushing commit to remote" {
|
||||||
|
INPUT_PUSH_OPTIONS="--force"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_PUSH_OPTIONS: --force"
|
||||||
|
assert_line "::debug::Apply push options --force"
|
||||||
|
assert_line "::debug::Push commit to remote branch master"
|
||||||
|
|
||||||
|
# TODO: Assert that on last push --force was used
|
||||||
|
# Assert that ref-log on local and remote are the same
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It can checkout a different branch" {
|
||||||
|
# Create foo-branch and then immediately switch back to master
|
||||||
|
git checkout -b foo
|
||||||
|
git checkout master
|
||||||
|
|
||||||
|
INPUT_BRANCH="foo"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_BRANCH value: foo"
|
||||||
|
assert_line "::debug::Push commit to remote branch foo"
|
||||||
|
|
||||||
|
# TODO: Assert a new branch "foo" exists on remote
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It uses existing branch name when pushing when INPUT_BRANCH is empty" {
|
||||||
|
INPUT_BRANCH=""
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_BRANCH value: "
|
||||||
|
assert_line --partial "::debug::git push origin"
|
||||||
|
|
||||||
|
# TODO: Assert that branch "master" was updated on remote
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "It uses existing branch when INPUT_BRANCH is empty and INPUT_TAGGING_MESSAGE is set" {
|
||||||
|
INPUT_BRANCH=""
|
||||||
|
INPUT_TAGGING_MESSAGE="v2.0.0"
|
||||||
|
|
||||||
|
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||||
|
|
||||||
|
run git_auto_commit
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
|
||||||
|
assert_line "::debug::Create tag v2.0.0"
|
||||||
|
assert_line "::debug::git push origin --tags"
|
||||||
|
|
||||||
|
# Assert a tag v2.0.0 has been created
|
||||||
|
run git tag
|
||||||
|
assert_output v2.0.0
|
||||||
|
|
||||||
|
# Assert tag v2.0.0 has been pushed to remote
|
||||||
|
run git ls-remote --tags --refs
|
||||||
|
assert_output --partial refs/tags/v2.0.0
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user