diff --git a/tests/commit.bats b/tests/commit.bats index b556e23..7ea94b5 100644 --- a/tests/commit.bats +++ b/tests/commit.bats @@ -1,9 +1,7 @@ #!/usr/bin/env bats setup() { - . shellmock - - # Build default world + # Build World export test_repository="${BATS_TEST_DIRNAME}/test_repo" rm -rf "${test_repository}" @@ -14,8 +12,7 @@ setup() { git add . >/dev/null 2>&1 git commit -m "Init Repo" >/dev/null 2>&1 - - # Set defaults INPUT variables + # Set default INPUT variables export INPUT_REPOSITORY="${BATS_TEST_DIRNAME}/test_repo" export INPUT_COMMIT_MESSAGE="Commit Message" export INPUT_BRANCH="master" @@ -27,6 +24,8 @@ setup() { export INPUT_TAGGING_MESSAGE="" export INPUT_PUSH_OPTIONS="" export INPUT_SKIP_DIRTY_CHECK=false + + . shellmock } teardown() { @@ -52,26 +51,60 @@ main() { [ "${lines[2]}" = "Working tree clean. Nothing to commit." ] } -@test "skip-dirty-on-clean-repo-failure" { +# TODO: Fix Issue where changes in git repo are not detected +@test "commit-changed-files-and-push-to-remote" { - # touch "${test_repository}/new-file.txt" + touch "${test_repository}"/new-file-{1,2,3}.txt - INPUT_SKIP_DIRTY_CHECK=true - INPUT_COMMIT_OPTIONS='--force' - - shellmock_expect git --type exact --match "status -s ." --output "fuck" - shellmock_expect git --type exact --match "checkout master" - shellmock_expect git --type exact --match "add ." - shellmock_expect git --type partial --match '-c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite --force' + shellmock_expect git --type partial --match "status" + shellmock_expect git --type partial --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: master" ] + [ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ] + [ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ] + [ "${lines[5]}" = "::debug::Apply commit options " ] + + shellmock_verify [ "${capture[0]}" = "git-stub status -s -- ." ] [ "${capture[1]}" = "git-stub checkout master" ] [ "${capture[2]}" = "git-stub add ." ] - [ "${capture[3]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite --force" ] + [ "${capture[3]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite " ] + [ "${capture[4]}" = "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 "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 checkout master" ] + [ "${capture[2]}" = "git-stub add ." ] + [ "${capture[3]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite " ] [ "${capture[4]}" = "git-stub push --set-upstream origin HEAD:master --tags" ] # Failed Exit Code @@ -81,6 +114,7 @@ main() { [ "${lines[1]}" = "::set-output name=changes_detected::true" ] [ "${lines[2]}" = "INPUT_BRANCH value: master" ] [ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ] - [ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: --force" ] - [ "${lines[5]}" = "::debug::Apply commit options --force" ] + [ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ] + [ "${lines[5]}" = "::debug::Apply commit options " ] } +