Skip to content

Commit

Permalink
Add pipefail to integration test
Browse files Browse the repository at this point in the history
Add pipefail to integration test when preparing the preview environment.
And add slack notifcation when preparing the preview environment failure.

Also, disable the error and exit immediately during `go test` to prevent
the integration test job exit immediately if the `go test` failure.

Signed-off-by: JenTing Hsiao <hsiaoairplane@gmail.com>
  • Loading branch information
jenting authored and roboquat committed May 25, 2022
1 parent e3019a5 commit 9aa403f
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions .werft/workspace-run-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,51 @@ pod:
- bash
- -c
- |
set -euo
set -euo pipefail
BRANCH="inte-test/"$(date +%Y%m%d%H%M%S)
FAILURE_COUNT=0
RUN_COUNT=0
declare -A FAILURE_TESTS
export WERFT_CREDENTIAL_HELPER=/workspace/dev/preview/werft-credential-helper.sh
function cleanup ()
{
werft log phase "slack notification" "slack notification"
context_name="{{ .Name }}"
context_repo="{{ .Repository.Repo }}"
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
if [ "${RUN_COUNT}" -eq "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs="Failed at preparing the preview environment"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
elif [ "${FAILURE_COUNT}" -ne "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs=""
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
title=$title"\n_Tests_: ${TEST_NAME}"
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
done
errs=$(echo "${errs}" | head)
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
else
title=":white_check_mark: *Workspace integration test pass*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
fi
curl -X POST \
-H 'Content-type: application/json' \
-d "${BODY}" \
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
werft log result "slack notification" "${PIPESTATUS[0]}"
werft log phase "clean up" "clean up"
git push origin "${BRANCH}" | werft log slice "clean up"
werft log slice "clean up" --done
Expand Down Expand Up @@ -114,18 +152,17 @@ pod:
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
WK_TEST_LIST=(/workspace/test/tests/components/content-service /workspace/test/tests/components/image-builder /workspace/test/tests/components/ws-daemon /workspace/test/tests/components/ws-manager /workspace/test/tests/workspace)
FAILURE_COUNT=0
declare -A FAILURE_TESTS
for TEST_PATH in "${WK_TEST_LIST[@]}"
do
TEST_NAME=$(basename "${TEST_PATH}")
echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
cd "${TEST_PATH}"
set +e
go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}"
set -e
RUN_COUNT=$((RUN_COUNT+1))
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
FAILURE_COUNT=$((FAILURE_COUNT+1))
FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log)
Expand All @@ -135,35 +172,6 @@ pod:
fi
done
werft log phase "slack notification" "slack notification"
context_name="{{ .Name }}"
context_repo="{{ .Repository.Repo }}"
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
if [ "${FAILURE_COUNT}" -ne "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs=""
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
title=$title"\n_Tests_: ${TEST_NAME}"
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
done
errs=$(echo "${errs}" | head)
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
else
title=":white_check_mark: *Workspace integration test pass*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
fi
curl -X POST \
-H 'Content-type: application/json' \
-d "${BODY}" \
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
werft log result "slack notification" "${PIPESTATUS[0]}"
exit $FAILURE_COUNT
plugins:
cron: "@midnight"

0 comments on commit 9aa403f

Please sign in to comment.