Skip to content

Commit

Permalink
Merge pull request #68 from planetscale/fix-ci
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
joemiller authored Aug 5, 2024
2 parents 5230710 + b330e62 commit 61331f3
Showing 1 changed file with 11 additions and 2 deletions.
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"
}

0 comments on commit 61331f3

Please sign in to comment.