-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Backward Compatibility with the old property
zoneName
. Added …
…Backward Compatibility Integration Test. Fixed Identation of integration tests and added project parameter for gcloud calls. Adjusted schema paterns. Added description for all the tests.
- Loading branch information
Showing
14 changed files
with
206 additions
and
61 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
16 changes: 16 additions & 0 deletions
16
dm/templates/dns_managed_zone/examples/dns_managed_zone_legacy.yaml
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,16 @@ | ||
# Example of the DNS managed zone template usage. | ||
# | ||
# In this example, a DNS managed zone is created with the use of | ||
# the old `zoneName` and `dnsName` properties. | ||
|
||
imports: | ||
- path: templates/dns_managed_zone/dns_managed_zone.py | ||
name: dns_managed_zone.py | ||
|
||
resources: | ||
- name: test-managed-zone | ||
type: dns_managed_zone.py | ||
properties: | ||
zoneName: test-managed-zone | ||
dnsName: foobar.local. | ||
description: 'My foobar DNS Managed Zone' |
86 changes: 86 additions & 0 deletions
86
dm/templates/dns_managed_zone/tests/integration/dns_mz_bkwrd_cmptb.bats
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,86 @@ | ||
#!/usr/bin/env bats | ||
|
||
source tests/helpers.bash | ||
|
||
TEST_NAME=$(basename "${BATS_TEST_FILENAME}" | cut -d '.' -f 1) | ||
|
||
# Create a random 10-char string and save it in a file. | ||
RANDOM_FILE="/tmp/${CLOUD_FOUNDATION_ORGANIZATION_ID}-${TEST_NAME}.txt" | ||
if [[ ! -e "${RANDOM_FILE}" ]]; then | ||
RAND=$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 10) | ||
echo ${RAND} > "${RANDOM_FILE}" | ||
fi | ||
|
||
# Set variables based on the random string saved in the file. | ||
# envsubst requires all variables used in the example/config to be exported. | ||
if [[ -e "${RANDOM_FILE}" ]]; then | ||
export RAND=$(cat "${RANDOM_FILE}") | ||
DEPLOYMENT_NAME="${CLOUD_FOUNDATION_PROJECT_ID}-${TEST_NAME}-${RAND}" | ||
# Replace underscores in the deployment name with dashes. | ||
DEPLOYMENT_NAME=${DEPLOYMENT_NAME//_/-} | ||
CONFIG=".${DEPLOYMENT_NAME}.yaml" | ||
export CLOUDDNS_ZONE_NAME="test-managed-zone-${RAND}" | ||
export CLOUDDNS_DNS_NAME="${RAND}.com." | ||
export CLOUDDNS_DESCRIPTION="Managed DNS Zone for Testing" | ||
fi | ||
|
||
########## HELPER FUNCTIONS ########## | ||
|
||
function create_config() { | ||
echo "Creating ${CONFIG}" | ||
envsubst < templates/dns_managed_zone/tests/integration/${TEST_NAME}.yaml > "${CONFIG}" | ||
} | ||
|
||
function delete_config() { | ||
echo "Deleting ${CONFIG}" | ||
rm -f "${CONFIG}" | ||
} | ||
|
||
function setup() { | ||
# Global setup; this is executed once per test file. | ||
if [ ${BATS_TEST_NUMBER} -eq 1 ]; then | ||
create_config | ||
fi | ||
|
||
# Per-test setup steps. | ||
} | ||
|
||
function teardown() { | ||
# Global teardown; this is executed once per test file. | ||
if [[ "$BATS_TEST_NUMBER" -eq "${#BATS_TEST_NAMES[@]}" ]]; then | ||
delete_config | ||
rm -f "${RANDOM_FILE}" | ||
fi | ||
|
||
# Per-test teardown steps. | ||
} | ||
|
||
|
||
########## TESTS ########## | ||
|
||
@test "Creating deployment ${DEPLOYMENT_NAME} from ${CONFIG}" { | ||
gcloud deployment-manager deployments create "${DEPLOYMENT_NAME}" \ | ||
--config "${CONFIG}" --project "${CLOUD_FOUNDATION_PROJECT_ID}" | ||
[[ "$status" -eq 0 ]] | ||
} | ||
|
||
@test "Verify if a managed zone with name $CLOUDDNS_ZONE_NAME was created" { | ||
run gcloud dns managed-zones list --format=flattened \ | ||
--project "${CLOUD_FOUNDATION_PROJECT_ID}" | ||
[[ "$status" -eq 0 ]] | ||
[[ "$output" =~ "${CLOUDDNS_ZONE_NAME}" ]] | ||
} | ||
|
||
@test "Verify if a DNS named ${CLOUDDNS_DNS_NAME} was created" { | ||
run gcloud dns managed-zones list --project "${CLOUD_FOUNDATION_PROJECT_ID}" | ||
[[ "$status" -eq 0 ]] | ||
[[ "$output" =~ "${CLOUDDNS_DNS_NAME}" ]] | ||
} | ||
|
||
@test "Deleting deployment ${DEPLOYMENT_NAME}" { | ||
gcloud deployment-manager deployments delete "${DEPLOYMENT_NAME}" \ | ||
-q --project "${CLOUD_FOUNDATION_PROJECT_ID}" | ||
run gcloud dns managed-zones list | ||
[[ "$status" -eq 0 ]] | ||
[[ ! "$output" =~ "${CLOUDDNS_ZONE_NAME}" ]] | ||
} |
19 changes: 19 additions & 0 deletions
19
dm/templates/dns_managed_zone/tests/integration/dns_mz_bkwrd_cmptb.yaml
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,19 @@ | ||
# Test Case: Backward Compatibility | ||
# Use Case: | ||
# You have updated CFT code base up to the latest version and now it works | ||
# with your old-style written templates in a slightly different way. | ||
# | ||
# F.e.: `zoneName` property is now replaced by `name` to align syntax with | ||
# the naming convention of the API. | ||
|
||
imports: | ||
- path: templates/dns_managed_zone/dns_managed_zone.py | ||
name: dns_managed_zone.py | ||
|
||
resources: | ||
- name: ${CLOUDDNS_ZONE_NAME}-resource | ||
type: dns_managed_zone.py | ||
properties: | ||
zoneName: ${CLOUDDNS_ZONE_NAME} | ||
dnsName: ${CLOUDDNS_DNS_NAME} | ||
description: ${CLOUDDNS_DESCRIPTION} |
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
10 changes: 8 additions & 2 deletions
10
dm/templates/dns_managed_zone/tests/integration/dns_mz_cross_project.yaml
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
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
Oops, something went wrong.