-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#736] Added tests for webhook
and docker
deployment.
#1257
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Tests for scripts/drevops/deploy-docker.sh script. | ||
# | ||
# shellcheck disable=SC2030,SC2031,SC2129,SC2155 | ||
|
||
load _helper.bash | ||
load _helper.deployment.bash | ||
|
||
@test "Missing DREVOPS_DEPLOY_DOCKER_MAP - deployment should not proceed" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
unset DREVOPS_DEPLOY_DOCKER_MAP | ||
run scripts/drevops/deploy-docker.sh | ||
assert_success | ||
assert_output_contains "Services map is not specified in DREVOPS_DEPLOY_DOCKER_MAP variable. Docker deployment will not continue." | ||
popd >/dev/null | ||
} | ||
|
||
@test "Docker deployment with valid DREVOPS_DEPLOY_DOCKER_MAP" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DREVOPS_DOCKER_IMAGE_TAG="test_latest" | ||
export DOCKER_REGISTRY="registry.example.com" | ||
provision_docker_config_file DOCKER_REGISTRY | ||
export DREVOPS_DEPLOY_DOCKER_MAP="service1=image1,service2=image2,service3=image3" | ||
|
||
declare -a STEPS=( | ||
"Started DOCKER deployment." | ||
"Processing service service1" | ||
"@docker compose ps -q service1 # service1_service_id" | ||
"Found \"service1\" service container with id \"service1_service_id\"." | ||
"Committing Docker image with name \"${DOCKER_REGISTRY}/image1:${DREVOPS_DOCKER_IMAGE_TAG}\"." | ||
"@docker commit service1_service_id ${DOCKER_REGISTRY}/image1:${DREVOPS_DOCKER_IMAGE_TAG} # sha256:service1_image_id" | ||
"Committed Docker image with id \"service1_image_id\"." | ||
"Pushing Docker image to the registry." | ||
"@docker push ${DOCKER_REGISTRY}/image1:${DREVOPS_DOCKER_IMAGE_TAG}" | ||
"Processing service service2" | ||
"@docker compose ps -q service2 # service2_service_id" | ||
"Found \"service2\" service container with id \"service2_service_id\"." | ||
"Committing Docker image with name \"${DOCKER_REGISTRY}/image2:${DREVOPS_DOCKER_IMAGE_TAG}\"." | ||
"@docker commit service2_service_id ${DOCKER_REGISTRY}/image2:${DREVOPS_DOCKER_IMAGE_TAG} # sha256:service2_image_id" | ||
"Committed Docker image with id \"service2_image_id\"." | ||
"Pushing Docker image to the registry." | ||
"@docker push ${DOCKER_REGISTRY}/image2:${DREVOPS_DOCKER_IMAGE_TAG}" | ||
"Processing service service3" | ||
"@docker compose ps -q service3 # service3_service_id" | ||
"Found \"service3\" service container with id \"service3_service_id\"." | ||
"Committing Docker image with name \"${DOCKER_REGISTRY}/image3:${DREVOPS_DOCKER_IMAGE_TAG}\"." | ||
"@docker commit service3_service_id ${DOCKER_REGISTRY}/image3:${DREVOPS_DOCKER_IMAGE_TAG} # sha256:service3_image_id" | ||
"Committed Docker image with id \"service3_image_id\"." | ||
"Pushing Docker image to the registry." | ||
"@docker push ${DOCKER_REGISTRY}/image3:${DREVOPS_DOCKER_IMAGE_TAG}" | ||
"Finished DOCKER deployment." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
run ./scripts/drevops/deploy-docker.sh | ||
assert_success | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
run scripts/drevops/deploy-docker.sh | ||
|
||
popd >/dev/null | ||
} | ||
|
||
@test "Docker deployment with services not running" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DREVOPS_DOCKER_IMAGE_TAG="test_latest" | ||
export DOCKER_REGISTRY="registry.example.com" | ||
provision_docker_config_file DOCKER_REGISTRY | ||
export DREVOPS_DEPLOY_DOCKER_MAP="service1=image1" | ||
|
||
declare -a STEPS=( | ||
"Started DOCKER deployment." | ||
"Processing service service1" | ||
"@docker compose ps -q service1" | ||
"Service \"service1\" is not running." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
run ./scripts/drevops/deploy-docker.sh | ||
assert_failure | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
run scripts/drevops/deploy-docker.sh | ||
|
||
popd >/dev/null | ||
} | ||
|
||
@test "Invalid DREVOPS_DEPLOY_DOCKER_MAP provided" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DREVOPS_DOCKER_IMAGE_TAG="test_latest" | ||
export DOCKER_REGISTRY="registry.example.com" | ||
|
||
# No key/value pair | ||
export DREVOPS_DEPLOY_DOCKER_MAP="service1" | ||
run ./scripts/drevops/deploy-docker.sh | ||
assert_failure | ||
assert_output_contains "invalid key/value pair \"service1\" provided." | ||
|
||
# using a space delimiter | ||
export DREVOPS_DEPLOY_DOCKER_MAP="service1=image1 service2=image2" | ||
run scripts/drevops/deploy-docker.sh | ||
assert_failure | ||
assert_output_contains "invalid key/value pair \"service1=image1 service2=image2\" provided." | ||
|
||
# No comma delimiter | ||
export DREVOPS_DEPLOY_DOCKER_MAP="service1=image1=service2=image2" | ||
run scripts/drevops/deploy-docker.sh | ||
assert_failure | ||
assert_output_contains "invalid key/value pair \"service1=image1=service2=image2\" provided." | ||
|
||
popd >/dev/null | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Test for webhook deployments. | ||
# | ||
# shellcheck disable=SC2030,SC2031,SC2129,SC2155 | ||
|
||
load _helper.bash | ||
load _helper.deployment.bash | ||
|
||
@test "Missing variable checks" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
unset DREVOPS_DEPLOY_WEBHOOK_URL | ||
unset DREVOPS_DEPLOY_WEBHOOK_METHOD | ||
unset DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS | ||
run scripts/drevops/deploy-webhook.sh | ||
assert_failure | ||
assert_output_contains "Missing required value for DREVOPS_DEPLOY_WEBHOOK_URL." | ||
mock_curl=$(mock_command "curl") | ||
mock_set_output "${mock_curl}" "200" 1 | ||
export DREVOPS_DEPLOY_WEBHOOK_URL="https://example.com" | ||
unset DREVOPS_DEPLOY_WEBHOOK_METHOD | ||
unset DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS | ||
run scripts/drevops/deploy-webhook.sh | ||
assert_success | ||
assert_output_not_contains "Missing required value for DREVOPS_DEPLOY_WEBHOOK_METHOD." | ||
assert_output_not_contains "Missing required value for DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS." | ||
popd >/dev/null | ||
} | ||
|
||
@test "Successful webhook deployment" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DREVOPS_DEPLOY_WEBHOOK_URL="https://example.com" | ||
export DREVOPS_DEPLOY_WEBHOOK_METHOD="GET" | ||
export DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS="200" | ||
mock_curl=$(mock_command "curl") | ||
mock_set_output "${mock_curl}" "${DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS}" 1 | ||
|
||
run scripts/drevops/deploy-webhook.sh | ||
assert_success | ||
assert_output_contains "Webhook call completed." | ||
assert_output_contains "Finished WEBHOOK deployment." | ||
popd >/dev/null | ||
} | ||
|
||
@test "Failed webhook deployment" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DREVOPS_DEPLOY_WEBHOOK_URL="https://example.com" | ||
export DREVOPS_DEPLOY_WEBHOOK_METHOD="GET" | ||
export DREVOPS_DEPLOY_WEBHOOK_RESPONSE_STATUS="200" | ||
mock_curl=$(mock_command "curl") | ||
mock_set_output "${mock_curl}" "400" 1 | ||
|
||
run scripts/drevops/deploy-webhook.sh | ||
assert_failure | ||
assert_output_contains "Unable to complete webhook deployment." | ||
popd >/dev/null | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Test for login-docker script. | ||
# | ||
# shellcheck disable=SC2030,SC2031,SC2129,SC2155 | ||
|
||
load _helper.bash | ||
load _helper.deployment.bash | ||
|
||
@test "Docker configuration present" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export DOCKER_REGISTRY="https://www.example.com" | ||
provision_docker_config_file $DOCKER_REGISTRY | ||
export HOME=${BUILD_DIR} | ||
run scripts/drevops/login-docker.sh | ||
assert_success | ||
assert_output_contains Already logged in to registry \"https://www.example.com\" | ||
popd >/dev/null | ||
} | ||
|
||
@test "DOCKER_REGISTRY, DOCKER_USER and DOCKER_PASS must be set" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
export HOME=${BUILD_DIR} | ||
unset DOCKER_USER | ||
unset DOCKER_PASS | ||
run scripts/drevops/login-docker.sh | ||
assert_success | ||
assert_output_not_contains "Missing required value for DOCKER_REGISTRY." | ||
assert_output_contains "Skipping login into Docker registry as either DOCKER_USER or DOCKER_PASS was not provided." | ||
export DOCKER_USER="test_user" | ||
run scripts/drevops/login-docker.sh | ||
assert_success | ||
assert_output_contains "Skipping login into Docker registry as either DOCKER_USER or DOCKER_PASS was not provided." | ||
mock_docker=$(mock_command "docker") | ||
mock_set_output "${mock_docker}" "Login Succeeded" 1 | ||
export DOCKER_PASS="test_pass" | ||
export DOCKER_REGISTRY="https://www.example.com" | ||
run scripts/drevops/login-docker.sh | ||
assert_success | ||
assert_equal "1" "$(mock_get_call_num "${mock_docker}" 1)" | ||
assert_output_contains "Logging in to registry \"https://www.example.com\"." | ||
popd >/dev/null | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently scripts have default values for these two environment variables and so check will currently not fail.