diff --git a/tests/suites/cli/display_clouds.sh b/tests/suites/cli/display_clouds.sh index 7fa8bcbedf80..489192e0ccae 100644 --- a/tests/suites/cli/display_clouds.sh +++ b/tests/suites/cli/display_clouds.sh @@ -45,6 +45,7 @@ EOF fi } +# Assess how clouds behaves when only expected clouds are defined. run_assess_clouds() { echo @@ -52,6 +53,7 @@ run_assess_clouds() { echo "" >>"${TEST_DIR}/juju/public-clouds.yaml" echo "" >>"${TEST_DIR}/juju/credentials.yaml" + #Remove the attributes added by display. i.e 'defined' attribute whose value is not "built-in". CLOUD_LIST=$(JUJU_DATA="${TEST_DIR}/juju" juju clouds --client --format=json 2>/dev/null | jq 'with_entries(select(.value.defined != "built-in"))') EXPECTED={} if [ "${CLOUD_LIST}" != "${EXPECTED}" ]; then @@ -79,9 +81,11 @@ EOF ) echo "${CLOUDS}" >>"${TEST_DIR}/juju/clouds.yaml" + # Remove the 'defined' and 'description' attributes CLOUD_LIST=$(JUJU_DATA="${TEST_DIR}/juju" juju clouds --client --format=json 2>/dev/null | jq -S 'with_entries(select( .value.defined != "built-in")) | with_entries((select(.value.defined == "local") | del(.value.defined) | del(.value.description)))') + # Remove the 'clouds' top level key and any redundant 'endpoint' key:value pair. EXPECTED=$(echo "${CLOUDS}" | yq -I0 -oj | jq -S '.[] | del(.clouds) | .[] |= ({endpoint} as $endpoint | .[] |= walk( (objects | select(contains($endpoint))) |= del(.endpoint) ))') @@ -90,18 +94,49 @@ EOF exit 1 fi +} + +# Assess how show-cloud behaves +run_assess_show_cloud() { + echo + + mkdir -p "${TEST_DIR}/juju" + echo "" >>"${TEST_DIR}/juju/public-clouds.yaml" + echo "" >>"${TEST_DIR}/juju/credentials.yaml" + + CLOUDS=$( + cat <<'EOF' + clouds: + finfolk-vmaas: + auth-types: + - oauth1 + endpoint: http://10.125.0.10:5240/MAAS/ + type: maas + vsphere: + auth-types: + - userpass + endpoint: 10.247.0.3 + regions: + QA: + endpoint: 10.247.0.3 + type: vsphere +EOF + ) + + echo "${CLOUDS}" >>"${TEST_DIR}/juju/clouds.yaml" + # Remove any key whose value is null. CLOUD_LIST=$(JUJU_DATA="${TEST_DIR}/juju" juju show-cloud finfolk-vmaas --format yaml --client 2>/dev/null | yq -I0 -oj | jq -S 'with_entries((select(.value!= null)))') EXPECTED=$( cat <<'EOF' | jq -S - { - "auth-types": [ - "oauth1" - ], - "defined": "local", - "description": "Metal As A Service", - "endpoint": "http://10.125.0.10:5240/MAAS/", - "type": "maas" - } + { + "auth-types": [ + "oauth1" + ], + "defined": "local", + "description": "Metal As A Service", + "endpoint": "http://10.125.0.10:5240/MAAS/", + "type": "maas" + } EOF ) @@ -124,5 +159,6 @@ test_display_clouds() { run "run_show_clouds" run "run_assess_clouds" + run "run_assess_show_cloud" ) }