Skip to content

Commit ce78391

Browse files
committed
Added tests for author name/email sourcing
1 parent ff8ade5 commit ce78391

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

tests/entrypoint.bats

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,79 @@ teardown() {
502502

503503
unstub curl
504504
}
505+
506+
@test "Creates a build with author from commit.commit when pusher is not available (status events)" {
507+
508+
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123"
509+
export INPUT_PIPELINE="my-org/my-pipeline"
510+
export GITHUB_EVENT_PATH="tests/status.json"
511+
export GITHUB_EVENT_NAME="status"
512+
513+
EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"Status Author","email":"[email protected]"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}'
514+
RESPONSE_JSON='{"web_url": "https://buildkite.com/build-url"}'
515+
516+
stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'"
517+
518+
run "${PWD}"/entrypoint.sh
519+
520+
assert_output --partial "Build created:"
521+
assert_output --partial "https://buildkite.com/build-url"
522+
assert_output --partial "::set-output name=json::$RESPONSE_JSON"
523+
assert_output --partial "::set-output name=url::https://buildkite.com/build-url"
524+
525+
assert_success
526+
527+
unstub curl
528+
}
529+
530+
@test "Creates a build with author from default parameters when no author in event" {
531+
532+
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123"
533+
export INPUT_PIPELINE="my-org/my-pipeline"
534+
export INPUT_COMMIT_AUTHOR_NAME="Default Name"
535+
export INPUT_COMMIT_AUTHOR_EMAIL="[email protected]"
536+
export GITHUB_EVENT_PATH="tests/no-author.json"
537+
export GITHUB_EVENT_NAME="create"
538+
539+
EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"Default Name","email":"[email protected]"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}'
540+
RESPONSE_JSON='{"web_url": "https://buildkite.com/build-url"}'
541+
542+
stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'"
543+
544+
run "${PWD}"/entrypoint.sh
545+
546+
assert_output --partial "Build created:"
547+
assert_output --partial "https://buildkite.com/build-url"
548+
assert_output --partial "::set-output name=json::$RESPONSE_JSON"
549+
assert_output --partial "::set-output name=url::https://buildkite.com/build-url"
550+
551+
assert_success
552+
553+
unstub curl
554+
}
555+
556+
@test "Pusher fields take precedence over default parameters" {
557+
558+
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123"
559+
export INPUT_PIPELINE="my-org/my-pipeline"
560+
export INPUT_COMMIT_AUTHOR_NAME="Default Name"
561+
export INPUT_COMMIT_AUTHOR_EMAIL="[email protected]"
562+
export GITHUB_EVENT_PATH="tests/push.json"
563+
export GITHUB_EVENT_NAME="push"
564+
565+
EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"[email protected]"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}'
566+
RESPONSE_JSON='{"web_url": "https://buildkite.com/build-url"}'
567+
568+
stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'"
569+
570+
run "${PWD}"/entrypoint.sh
571+
572+
assert_output --partial "Build created:"
573+
assert_output --partial "https://buildkite.com/build-url"
574+
assert_output --partial "::set-output name=json::$RESPONSE_JSON"
575+
assert_output --partial "::set-output name=url::https://buildkite.com/build-url"
576+
577+
assert_success
578+
579+
unstub curl
580+
}

tests/no-author.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ref": "refs/heads/main"
3+
}

tests/status.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commit": {
3+
"commit": {
4+
"author": {
5+
"name": "Status Author",
6+
"email": "[email protected]"
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)