Skip to content

Commit

Permalink
Init test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 committed Apr 19, 2024
1 parent 9f4a5e2 commit b82ac1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .scaffold/tests/bats/notify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,31 @@ load _helper.bash

popd >/dev/null || exit 1
}

@test "Notify: webhook" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

mock_curl=$(mock_command "curl")

mock_set_output "${mock_curl}" "200" 1

export DREVOPS_NOTIFY_ENVIRONMENT_URL="https://example-environment-notifcation.com"
export DREVOPS_NOTIFY_WEBHOOK_URL="https://example-webhook-url.com"
export DREVOPS_NOTIFY_WEBHOOK_METHOD="POST"
export DREVOPS_NOTIFY_WEBHOOK_CUSTOM_HEADERS='[{"name": "Content-type", "value": "application/json"},{"name": "Authorization", "value": "Bearer API_KEY"}]'
export DREVOPS_NOTIFY_WEBHOOK_MESSAGE_BODY='{"channel": "XXX", "message": "Hello there"}'
export DREVOPS_NOTIFY_WEBHOOK_CUSTOM_PARAMETERS_AND_SECRETS='[{"name": "API_KEY", "value": "this-is-api-key"},{"name": "PASSWORD", "value": "this-is-password"}]'

run ./scripts/drevops/notify.sh
assert_success

assert_output_contains "Started dispatching notifications."

assert_output_contains "Started Webhook notification."

assert_output_contains "Finished Webhook notification."

assert_output_contains "Finished dispatching notifications."

popd >/dev/null || exit 1
}
3 changes: 3 additions & 0 deletions scripts/drevops/notify-webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ if [[ ${response_http_code} == "200" ]]; then
pass "Notified to webhook ${DREVOPS_NOTIFY_WEBHOOK_URL}."

Check warning on line 101 in scripts/drevops/notify-webhook.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/notify-webhook.sh#L99-L101

Added lines #L99 - L101 were not covered by tests
else
fail "Unable to notify to webhook ${DREVOPS_NOTIFY_WEBHOOK_URL}."
exit 1

Check warning on line 104 in scripts/drevops/notify-webhook.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/notify-webhook.sh#L103-L104

Added lines #L103 - L104 were not covered by tests
fi

pass "Finished Webhook notification."

Check warning on line 107 in scripts/drevops/notify-webhook.sh

View check run for this annotation

Codecov / codecov/patch

scripts/drevops/notify-webhook.sh#L107

Added line #L107 was not covered by tests

1 comment on commit b82ac1d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.