-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52a3381
commit 1af61c2
Showing
1 changed file
with
80 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,48 +8,75 @@ load _helper.bash | |
|
||
@test "Notify: skip" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Skipping dispatching notifications." | ||
"- Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_SKIP=1 | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
assert_output_contains "Skipping dispatching notifications." | ||
assert_output_not_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: unsupported event" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Unsupported event customevent provided." | ||
"- Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_EVENT="customevent" | ||
run ./scripts/drevops/notify.sh | ||
assert_failure | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
assert_output_contains "Unsupported event customevent provided." | ||
assert_output_not_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: custom type" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="customtype" | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
assert_output_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: email" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started email notification." | ||
"Notification email(s) sent to: [email protected], [email protected]" | ||
"Finished email notification." | ||
"Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="email" | ||
export DREVOPS_NOTIFY_PROJECT="testproject" | ||
export DRUPAL_SITE_EMAIL="[email protected]" | ||
|
@@ -59,13 +86,7 @@ load _helper.bash | |
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
|
||
assert_output_contains "Started email notification." | ||
assert_output_contains "Notification email(s) sent to: [email protected], [email protected]" | ||
assert_output_contains "Finished email notification." | ||
|
||
assert_output_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
@@ -114,9 +135,17 @@ load _helper.bash | |
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
app_id="123456789" | ||
mock_curl=$(mock_command "curl") | ||
|
||
mock_set_output "${mock_curl}" "{\"id\": \"${app_id}\", \"othervar\": \"54321\"}" 1 | ||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for pre_deployment event." | ||
"@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"mybranch\", \"environment\": \"PR\", \"auto_merge\": false} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" | ||
"Marked deployment as started." | ||
"Finished GitHub notification for pre_deployment event." | ||
"Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="pre_deployment" | ||
|
@@ -126,16 +155,7 @@ load _helper.bash | |
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
|
||
assert_output_contains "Started GitHub notification for pre_deployment event." | ||
|
||
assert_equal '-X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {"ref":"mybranch", "environment": "PR", "auto_merge": false}' "$(mock_get_call_args "${mock_curl}" 1)" | ||
|
||
assert_output_contains "Marked deployment as started." | ||
assert_output_contains "Finished GitHub notification for pre_deployment event." | ||
|
||
assert_output_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
@@ -146,8 +166,16 @@ load _helper.bash | |
app_id="123456789" | ||
mock_curl=$(mock_command "curl") | ||
|
||
mock_set_output "${mock_curl}" "[{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"987654321\", \"othervar\": \"12345\"}]" 1 | ||
mock_set_output "${mock_curl}" '{"state": "success", "othervar": "54321"}' 2 | ||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for post_deployment event." | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=mybranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"987654321\", \"othervar\": \"12345\"}]" | ||
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/123456789/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}" | ||
"Marked deployment as finished." | ||
"Finished GitHub notification for post_deployment event." | ||
"Finished dispatching notifications." | ||
) | ||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="post_deployment" | ||
|
@@ -158,17 +186,7 @@ load _helper.bash | |
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
|
||
assert_output_contains "Started GitHub notification for post_deployment event." | ||
|
||
assert_equal "-X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=mybranch" "$(mock_get_call_args "${mock_curl}" 1)" | ||
assert_equal '-X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/123456789/statuses -s -d {"state":"success", "environment_url": "https://develop.testproject.com"}' "$(mock_get_call_args "${mock_curl}" 2)" | ||
|
||
assert_output_contains "Marked deployment as finished." | ||
assert_output_contains "Finished GitHub notification for post_deployment event." | ||
|
||
assert_output_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
@@ -180,14 +198,27 @@ load _helper.bash | |
assignee_account_id="987654321c20165700ede21g" | ||
comment_id="1234" | ||
|
||
mock_curl=$(mock_command "curl") | ||
|
||
mock_set_output "${mock_curl}" "{\"accountId\": \"${account_id}\", \"othervar\": \"54321\"}" 1 | ||
mock_set_output "${mock_curl}" "{\"id\": \"${comment_id}\", \"othervar\": \"54321\"}" 2 | ||
mock_set_output "${mock_curl}" '{"expand":"transitions","transitions":[{"id":"123","name":"QA"},{"id":"456","name":"Closed"}]}' 3 | ||
mock_set_output "${mock_curl}" "" 4 | ||
mock_set_output "${mock_curl}" "[{\"accountId\": \"${assignee_account_id}\", \"othervar\": \"54321\"}, {\"accountId\": \"01987654321c20165700edeg\", \"othervar\": \"54321\"}]" 5 | ||
mock_set_output "${mock_curl}" "" 6 | ||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started JIRA notification." | ||
"Found issue proj-1234." | ||
"- Branch feature/proj-1234-some-description does not contain issue number." | ||
"Checking API access." | ||
"@curl -s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json https://jira.atlassian.com/rest/api/3/myself # {\"accountId\": \"${account_id}\", \"othervar\": \"54321\"}" | ||
"Posting a comment." | ||
"@curl -s -X POST -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/comment --data {\"body\": {\"type\": \"doc\", \"version\": 1, \"content\": [{\"type\": \"paragraph\", \"content\": [{\"type\": \"text\",\"text\": \"Deployed to \"},{\"type\": \"inlineCard\",\"attrs\": {\"url\": \"https://develop.testproject.com\"}}]}]}} # {\"id\": \"${comment_id}\", \"othervar\": \"54321\"}" | ||
"Posted comment with ID ${comment_id}." | ||
"Transitioning issue to QA" | ||
"Discovering transition ID for QA" | ||
"@curl -s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/transitions # {\"expand\":\"transitions\",\"transitions\":[{\"id\":\"123\",\"name\":\"QA\"},{\"id\":\"456\",\"name\":\"Closed\"}]}" | ||
"@curl -s -X POST -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/transitions --data { \"transition\": {\"id\": \"123\"}} # " | ||
"Transitioned issue to QA" | ||
"Assigning issue to [email protected]" | ||
"Discovering user ID for [email protected]" | ||
"@curl -s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/user/assignable/[email protected]&issueKey=proj-1234 # [{\"accountId\": \"${assignee_account_id}\", \"othervar\": \"54321\"}, {\"accountId\": \"01987654321c20165700edeg\", \"othervar\": \"54321\"}]" | ||
"@curl -s -X PUT -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/assignee --data { \"accountId\": \"987654321c20165700ede21g\"} # " | ||
) | ||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="jira" | ||
export DREVOPS_NOTIFY_JIRA_USER="[email protected]" | ||
|
@@ -199,35 +230,7 @@ load _helper.bash | |
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
assert_output_contains "Started dispatching notifications." | ||
|
||
assert_output_contains "Started JIRA notification." | ||
assert_output_contains "Found issue proj-1234." | ||
assert_output_not_contains "Branch feature/proj-1234-some-description does not contain issue number." | ||
|
||
# Authenticate and get an account id. | ||
assert_output_contains "Checking API access." | ||
assert_equal "-s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json https://jira.atlassian.com/rest/api/3/myself" "$(mock_get_call_args "${mock_curl}" 1)" | ||
|
||
assert_output_contains "Posting a comment." | ||
assert_equal '-s -X POST -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/comment --data {"body": {"type": "doc", "version": 1, "content": [{"type": "paragraph", "content": [{"type": "text","text": "Deployed to "},{"type": "inlineCard","attrs": {"url": "https://develop.testproject.com"}}]}]}}' "$(mock_get_call_args "${mock_curl}" 2)" | ||
assert_output_contains "Posted comment with ID ${comment_id}." | ||
|
||
assert_output_contains "Transitioning issue to QA" | ||
assert_output_contains "Discovering transition ID for QA" | ||
assert_equal "-s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/transitions" "$(mock_get_call_args "${mock_curl}" 3)" | ||
assert_equal '-s -X POST -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/transitions --data { "transition": {"id": "123"}}' "$(mock_get_call_args "${mock_curl}" 4)" | ||
assert_output_contains "Transitioned issue to QA" | ||
|
||
assert_output_contains "Assigning issue to [email protected]" | ||
assert_output_contains "Discovering user ID for [email protected]" | ||
assert_equal "-s -X GET -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/user/assignable/[email protected]&issueKey=proj-1234" "$(mock_get_call_args "${mock_curl}" 5)" | ||
assert_equal '-s -X PUT -H Authorization: Basic am9obi5kb2VAZXhhbXBsZS5jb206dG9rZW4xMjM0NQ== -H Content-Type: application/json --url https://jira.atlassian.com/rest/api/3/issue/proj-1234/assignee --data { "accountId": "987654321c20165700ede21g"}' "$(mock_get_call_args "${mock_curl}" 6)" | ||
assert_output_contains "Assigned issue to [email protected]" | ||
|
||
assert_output_contains "Finished JIRA notification." | ||
|
||
assert_output_contains "Finished dispatching notifications." | ||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} |