Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #68

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tests/entrypoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"

setup() {
export GITHUB_WORKSPACE=/tmp
#export DEBUG=1
}

@test "parses git status output and generates correct flags for ghcommit" {
Expand All @@ -17,6 +18,8 @@ setup() {
local empty='false'
local file_pattern='.'

export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"

# NOTE: we are passing our hand-crafted fixture through `tr` to convert newlines to nulls since
# we run `git status -z` which uses null terminators. The newlines are meant to make the file easier
# to modify and prevent cat from removing the leading space on lines/entries since that is a part
Expand All @@ -26,11 +29,13 @@ setup() {
"status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-1 | tr '\n' '\0'"

stub ghcommit \
'-b main -r org/repo -m msg --add=README.md --add=foo.txt --add=new.file --delete=old.file --delete=\""a path with spaces oh joy/file.txt\"" : echo Success'
'-b main -r org/repo -m msg --add=README.md --add=foo.txt --add=new.file --delete=old.file --delete=\""a path with spaces oh joy/file.txt\"" : echo Success. New commit: https://localhost/foo'

run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "Success"
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
}

@test "no changes" {
Expand All @@ -56,14 +61,18 @@ setup() {
local empty='true'
local file_pattern='.'

export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"

stub git \
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
"status -s --porcelain=v1 -z -- . : echo"

stub ghcommit \
'-b main -r org/repo -m msg --empty : echo Success'
'-b main -r org/repo -m msg --empty : echo Success. New commit: https://localhost/foo'

run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "Success"
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
}