github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/credential/controller_credentials.sh (about)

     1  run_controller_credentials() {
     2  	echo
     3  
     4  	juju show-cloud --controller "${BOOTSTRAPPED_JUJU_CTRL_NAME}" aws 2>/dev/null || juju add-cloud --controller "${BOOTSTRAPPED_JUJU_CTRL_NAME}" aws --force
     5  	juju add-credential aws -f "./tests/suites/credential/credentials-data/fake-credentials.yaml" --controller "${BOOTSTRAPPED_JUJU_CTRL_NAME}"
     6  	OUT=$(juju credentials --controller "${BOOTSTRAPPED_JUJU_CTRL_NAME}" --format=json 2>/dev/null | jq '.[].aws."cloud-credentials"')
     7  
     8  	EXPECTED=$(
     9  		cat <<'EOF'
    10    "fake-credential-name": {
    11      "auth-type": "access-key",
    12      "details": {
    13        "access-key": "fake-access-key"
    14      }
    15    }
    16  EOF
    17  	)
    18  	# Controller has more than one credential, just check the one we added.
    19  	if [[ ${OUT} != *"${EXPECTED}"* ]]; then
    20  		echo "expected ${EXPECTED}, got ${OUT}"
    21  		exit 1
    22  	fi
    23  
    24  	OUT=$(juju credentials --controller ${BOOTSTRAPPED_JUJU_CTRL_NAME} --show-secrets --format=json 2>/dev/null | jq '.[].aws."cloud-credentials"')
    25  	EXPECTED=$(
    26  		cat <<'EOF'
    27    "fake-credential-name": {
    28      "auth-type": "access-key",
    29      "details": {
    30        "access-key": "fake-access-key",
    31        "secret-key": "fake-secret-key"
    32      }
    33    }
    34  
    35  EOF
    36  	)
    37  	# Controller has more than one credential, just check the one we added.
    38  	if [[ ${OUT} != *"${EXPECTED}"* ]]; then
    39  		echo "expected ${EXPECTED}, got ${OUT}"
    40  		exit 1
    41  	fi
    42  }
    43  
    44  test_controller_credentials() {
    45  	if [ "$(skip 'test_credentials')" ]; then
    46  		echo "==> TEST SKIPPED: credentials"
    47  		return
    48  	fi
    49  
    50  	(
    51  		set_verbosity
    52  
    53  		cd .. || exit
    54  
    55  		file="${TEST_DIR}/test-credential.log"
    56  		bootstrap "test-credential" "${file}"
    57  
    58  		run "run_controller_credentials"
    59  		# TODO: remove credential afterwards - even if test fails
    60  		# juju remove-credential aws fake-credential-name || true
    61  
    62  		destroy_controller "test-credential"
    63  	)
    64  }