Skip to content

Commit 77030a6

Browse files
committed
Split notification tests into multiple files.
1 parent f177774 commit 77030a6

File tree

7 files changed

+664
-614
lines changed

7 files changed

+664
-614
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bats
2+
##
3+
# Unit tests for email notifications (notify.sh).
4+
#
5+
#shellcheck disable=SC2030,SC2031,SC2034
6+
7+
load ../_helper.bash
8+
9+
@test "Notify: email, branch" {
10+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
11+
12+
export VORTEX_NOTIFY_CHANNELS="email"
13+
export VORTEX_NOTIFY_PROJECT="testproject"
14+
export DRUPAL_SITE_EMAIL="[email protected]"
15+
export VORTEX_NOTIFY_EMAIL_RECIPIENTS="[email protected]|John Doe, [email protected]|Jane Doe, [email protected]"
16+
export VORTEX_NOTIFY_REF="develop"
17+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
18+
run ./scripts/vortex/notify.sh
19+
assert_success
20+
21+
assert_output_contains "Started dispatching notifications."
22+
23+
assert_output_contains "Started email notification."
24+
assert_output_contains "Notification email(s) sent to: [email protected], [email protected], [email protected]"
25+
assert_output_contains "Finished email notification."
26+
27+
assert_output_contains 'testproject deployment notification of "develop" branch'
28+
assert_output_contains 'Site testproject "develop" branch has been deployed'
29+
assert_output_contains "and is available at https://develop.testproject.com."
30+
31+
assert_output_contains "Finished dispatching notifications."
32+
33+
popd >/dev/null || exit 1
34+
}
35+
36+
@test "Notify: email, PR" {
37+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
38+
39+
export VORTEX_NOTIFY_CHANNELS="email"
40+
export VORTEX_NOTIFY_PROJECT="testproject"
41+
export DRUPAL_SITE_EMAIL="[email protected]"
42+
export VORTEX_NOTIFY_EMAIL_RECIPIENTS="[email protected]|John Doe, [email protected]|Jane Doe"
43+
export VORTEX_NOTIFY_REF="develop"
44+
export VORTEX_NOTIFY_PR_NUMBER="123"
45+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
46+
run ./scripts/vortex/notify.sh
47+
assert_success
48+
49+
assert_output_contains "Started dispatching notifications."
50+
51+
assert_output_contains "Started email notification."
52+
assert_output_contains "Notification email(s) sent to: [email protected], [email protected]"
53+
assert_output_contains "Finished email notification."
54+
55+
assert_output_contains 'testproject deployment notification of "PR-123"'
56+
assert_output_contains 'Site testproject "PR-123" has been deployed'
57+
assert_output_contains "and is available at https://develop.testproject.com."
58+
59+
assert_output_contains "Finished dispatching notifications."
60+
61+
popd >/dev/null || exit 1
62+
}
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
#!/usr/bin/env bats
2+
##
3+
# Unit tests for GitHub notifications (notify.sh).
4+
#
5+
#shellcheck disable=SC2030,SC2031,SC2034
6+
7+
load ../_helper.bash
8+
9+
@test "Notify: github, pre_deployment" {
10+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
11+
12+
app_id="123456789"
13+
14+
declare -a STEPS=(
15+
"Started dispatching notifications."
16+
"Started GitHub notification for pre_deployment event."
17+
"@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\":\"existingbranch\", \"environment\": \"PR\", \"auto_merge\": false, \"required_contexts\": []} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}"
18+
"Marked deployment as started."
19+
"Finished GitHub notification for pre_deployment event."
20+
"Finished dispatching notifications."
21+
)
22+
23+
mocks="$(run_steps "setup")"
24+
25+
export VORTEX_NOTIFY_CHANNELS="github"
26+
export VORTEX_NOTIFY_EVENT="pre_deployment"
27+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
28+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
29+
export VORTEX_NOTIFY_BRANCH="existingbranch"
30+
run ./scripts/vortex/notify.sh
31+
assert_success
32+
33+
run_steps "assert" "${mocks[@]}"
34+
35+
popd >/dev/null || exit 1
36+
}
37+
38+
@test "Notify: github, pre_deployment, PR" {
39+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
40+
41+
app_id="123456789"
42+
43+
declare -a STEPS=(
44+
"Started dispatching notifications."
45+
"Started GitHub notification for pre_deployment event."
46+
"@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\":\"existingbranch\", \"environment\": \"PR-123\", \"auto_merge\": false, \"required_contexts\": []} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}"
47+
"Marked deployment as started."
48+
"Finished GitHub notification for pre_deployment event."
49+
"Finished dispatching notifications."
50+
)
51+
52+
mocks="$(run_steps "setup")"
53+
54+
export VORTEX_NOTIFY_CHANNELS="github"
55+
export VORTEX_NOTIFY_EVENT="pre_deployment"
56+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
57+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
58+
export VORTEX_NOTIFY_BRANCH="existingbranch"
59+
export VORTEX_NOTIFY_PR_NUMBER="123"
60+
run ./scripts/vortex/notify.sh
61+
assert_success
62+
63+
run_steps "assert" "${mocks[@]}"
64+
65+
popd >/dev/null || exit 1
66+
}
67+
68+
@test "Notify: github, pre_deployment, longer ID" {
69+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
70+
71+
app_id="12345678987"
72+
73+
declare -a STEPS=(
74+
"Started dispatching notifications."
75+
"Started GitHub notification for pre_deployment event."
76+
"@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\":\"existingbranch\", \"environment\": \"PR\", \"auto_merge\": false, \"required_contexts\": []} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}"
77+
"Marked deployment as started."
78+
"Finished GitHub notification for pre_deployment event."
79+
"Finished dispatching notifications."
80+
)
81+
82+
mocks="$(run_steps "setup")"
83+
84+
export VORTEX_NOTIFY_CHANNELS="github"
85+
export VORTEX_NOTIFY_EVENT="pre_deployment"
86+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
87+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
88+
export VORTEX_NOTIFY_BRANCH="existingbranch"
89+
run ./scripts/vortex/notify.sh
90+
assert_success
91+
92+
run_steps "assert" "${mocks[@]}"
93+
94+
popd >/dev/null || exit 1
95+
}
96+
97+
@test "Notify: github, pre_deployment, failure" {
98+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
99+
100+
declare -a STEPS=(
101+
"Started dispatching notifications."
102+
"Started GitHub notification for pre_deployment event."
103+
'@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":"nonexistingbranch", "environment": "PR", "auto_merge": false, "required_contexts": []} # {"message": "No ref found for: nonexistingbranch","documentation_url": "https://docs.github.com/rest/deployments/deployments#create-a-deployment","status": "422"}'
104+
"Failed to get a deployment ID for a pre_deployment operation. Payload:"
105+
"Wait for GitHub checks to finish and try again."
106+
"-Marked deployment as finished."
107+
)
108+
109+
mocks="$(run_steps "setup")"
110+
111+
export VORTEX_NOTIFY_CHANNELS="github"
112+
export VORTEX_NOTIFY_EVENT="pre_deployment"
113+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
114+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
115+
export VORTEX_NOTIFY_BRANCH="nonexistingbranch"
116+
run ./scripts/vortex/notify.sh
117+
assert_failure
118+
119+
run_steps "assert" "${mocks[@]}"
120+
121+
popd >/dev/null || exit 1
122+
}
123+
124+
@test "Notify: github, post_deployment" {
125+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
126+
127+
app_id="123456789"
128+
mock_curl=$(mock_command "curl")
129+
130+
declare -a STEPS=(
131+
"Started dispatching notifications."
132+
"Started GitHub notification for post_deployment event."
133+
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]"
134+
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}"
135+
"Marked deployment as finished."
136+
"Finished GitHub notification for post_deployment event."
137+
"Finished dispatching notifications."
138+
)
139+
mocks="$(run_steps "setup")"
140+
141+
export VORTEX_NOTIFY_CHANNELS="github"
142+
export VORTEX_NOTIFY_EVENT="post_deployment"
143+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
144+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
145+
export VORTEX_NOTIFY_BRANCH="existingbranch"
146+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
147+
run ./scripts/vortex/notify.sh
148+
assert_success
149+
150+
run_steps "assert" "${mocks[@]}"
151+
152+
popd >/dev/null || exit 1
153+
}
154+
155+
@test "Notify: github, post_deployment, longer ID" {
156+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
157+
158+
app_id="12345678987"
159+
mock_curl=$(mock_command "curl")
160+
161+
declare -a STEPS=(
162+
"Started dispatching notifications."
163+
"Started GitHub notification for post_deployment event."
164+
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]"
165+
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}"
166+
"Marked deployment as finished."
167+
"Finished GitHub notification for post_deployment event."
168+
"Finished dispatching notifications."
169+
)
170+
mocks="$(run_steps "setup")"
171+
172+
export VORTEX_NOTIFY_CHANNELS="github"
173+
export VORTEX_NOTIFY_EVENT="post_deployment"
174+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
175+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
176+
export VORTEX_NOTIFY_BRANCH="existingbranch"
177+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
178+
run ./scripts/vortex/notify.sh
179+
assert_success
180+
181+
run_steps "assert" "${mocks[@]}"
182+
183+
popd >/dev/null || exit 1
184+
}
185+
186+
@test "Notify: github, post_deployment, failure to get id" {
187+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
188+
189+
mock_curl=$(mock_command "curl")
190+
191+
declare -a STEPS=(
192+
"Started dispatching notifications."
193+
"Started GitHub notification for post_deployment event."
194+
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=nonexistingbranch # []"
195+
"Failed to get a deployment ID for a post_deployment operation. Payload:"
196+
"Check that a pre_deployment notification was dispatched."
197+
"-Marked deployment as finished."
198+
)
199+
mocks="$(run_steps "setup")"
200+
201+
export VORTEX_NOTIFY_CHANNELS="github"
202+
export VORTEX_NOTIFY_EVENT="post_deployment"
203+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
204+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
205+
export VORTEX_NOTIFY_BRANCH="nonexistingbranch"
206+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
207+
run ./scripts/vortex/notify.sh
208+
assert_failure
209+
210+
run_steps "assert" "${mocks[@]}"
211+
212+
popd >/dev/null || exit 1
213+
}
214+
215+
@test "Notify: github, post_deployment, failure to set status" {
216+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
217+
218+
app_id="12345678987"
219+
mock_curl=$(mock_command "curl")
220+
221+
declare -a STEPS=(
222+
"Started dispatching notifications."
223+
"Started GitHub notification for post_deployment event."
224+
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]"
225+
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"notsuccess\", \"othervar\": \"54321\"}"
226+
"Previous deployment was found, but was unable to update the deployment status. Payload:"
227+
"-Marked deployment as finished."
228+
)
229+
mocks="$(run_steps "setup")"
230+
231+
export VORTEX_NOTIFY_CHANNELS="github"
232+
export VORTEX_NOTIFY_EVENT="post_deployment"
233+
export VORTEX_NOTIFY_GITHUB_TOKEN="token12345"
234+
export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo"
235+
export VORTEX_NOTIFY_BRANCH="existingbranch"
236+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
237+
run ./scripts/vortex/notify.sh
238+
assert_failure
239+
240+
run_steps "assert" "${mocks[@]}"
241+
242+
popd >/dev/null || exit 1
243+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bats
2+
##
3+
# Unit tests for JIRA notifications (notify.sh).
4+
#
5+
#shellcheck disable=SC2030,SC2031,SC2034
6+
7+
load ../_helper.bash
8+
9+
@test "Notify: jira" {
10+
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
11+
12+
account_id="123456789020165700ede21g"
13+
assignee_account_id="987654321c20165700ede21g"
14+
comment_id="1234"
15+
16+
# shellcheck disable=SC2034
17+
declare -a STEPS=(
18+
"Started dispatching notifications."
19+
"Started JIRA notification."
20+
"Extracting issue"
21+
"Found issue proj-1234."
22+
"- Branch feature/proj-1234-some-description does not contain issue number."
23+
"Checking API access."
24+
"Creating API token"
25+
"@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\"}"
26+
"Posting a comment."
27+
"@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\"}"
28+
"Posted comment with ID ${comment_id}."
29+
"Transitioning issue to QA"
30+
"Discovering transition ID for QA"
31+
'@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"}]}'
32+
'@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"}} # '
33+
"Transitioned issue to QA"
34+
"Assigning issue to [email protected]"
35+
"Discovering user ID for [email protected]"
36+
"@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\"}]"
37+
'@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"} # '
38+
)
39+
40+
mocks="$(run_steps "setup")"
41+
42+
export VORTEX_NOTIFY_CHANNELS="jira"
43+
export VORTEX_NOTIFY_JIRA_USER="[email protected]"
44+
export VORTEX_NOTIFY_JIRA_TOKEN="token12345"
45+
export VORTEX_NOTIFY_BRANCH="feature/proj-1234-some-description"
46+
export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com"
47+
export VORTEX_NOTIFY_JIRA_TRANSITION="QA"
48+
export VORTEX_NOTIFY_JIRA_ASSIGNEE="[email protected]"
49+
run ./scripts/vortex/notify.sh
50+
assert_success
51+
52+
run_steps "assert" "${mocks[@]}"
53+
54+
popd >/dev/null || exit 1
55+
}

0 commit comments

Comments
 (0)