-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
4c7fbbd
commit fbd8070
Showing
4 changed files
with
224 additions
and
0 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
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 | ||
} |
fbd8070
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.
🎉 Published on https://drevops-scaffold-docs.netlify.app as production
🚀 Deployed on https://660fa48041e16c5bb0f2bc9c--drevops-scaffold-docs.netlify.app