Skip to content

Commit

Permalink
split into separate tests to match the old python test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
evanson committed Aug 11, 2022
1 parent 95b00d3 commit d148257
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions tests/suites/cli/display_clouds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ EOF
fi
}

# Assess how clouds behaves when only expected clouds are defined.
run_assess_clouds() {
echo

mkdir -p "${TEST_DIR}/juju"
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
Expand Down Expand Up @@ -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)
))')
Expand All @@ -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
)

Expand All @@ -124,5 +159,6 @@ test_display_clouds() {

run "run_show_clouds"
run "run_assess_clouds"
run "run_assess_show_cloud"
)
}

0 comments on commit d148257

Please sign in to comment.