Add _aliapi_check_vars helper function
This commit is contained in:
parent
731434bc05
commit
3c2942b31c
|
@ -10,10 +10,7 @@ unset _aliapi_command
|
|||
|
||||
# aliapi_rpc <http_method> <host> <api_version> <api_action> [<--key> <value>...]
|
||||
aliapi_rpc() {
|
||||
if [[ ! -v AliAccessKeyId || ! -v AliAccessKeySecret ]]; then
|
||||
echo "Aliyun OpenAPI SDK: 'AliAccessKeyId' or 'AliAccessKeySecret' environment variable not found" >&2
|
||||
return 3
|
||||
fi
|
||||
_aliapi_check_vars || return $?
|
||||
|
||||
if [[ $# -lt 4 ]];then
|
||||
echo "aliapi_rpc: not enough parameters" >&2
|
||||
|
@ -78,6 +75,13 @@ aliapi_rpc() {
|
|||
[[ $_http_code -eq 200 ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
_aliapi_check_vars() {
|
||||
if [[ ! -v AliAccessKeyId || ! -v AliAccessKeySecret ]]; then
|
||||
echo "Aliyun OpenAPI SDK: 'AliAccessKeyId' or 'AliAccessKeySecret' environment variable not found" >&2
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
_aliapi_signature_rpc() {
|
||||
local -u _http_method=$1
|
||||
local _str _query_str _sign_str
|
||||
|
|
23
test.bats.sh
23
test.bats.sh
|
@ -6,6 +6,12 @@ setup() {
|
|||
source AliyunOpenApiSDK.sh
|
||||
}
|
||||
|
||||
skip_no_aliaccess() {
|
||||
if [[ ! -v AliAccessKeyId || ! -v AliAccessKeySecret ]]; then
|
||||
skip "'AliAccessKeyId' or 'AliAccessKeySecret' environment variable not found"
|
||||
fi
|
||||
}
|
||||
|
||||
test_signature_nonce() { #@test
|
||||
run _aliapi_signature_nonce
|
||||
nonceA=$output
|
||||
|
@ -46,20 +52,27 @@ test_urlencode() { #@test
|
|||
[[ $output == "new%0Aline%0Atest" ]]
|
||||
}
|
||||
|
||||
test_rpc_api() { #@test
|
||||
if [[ ! -v AliAccessKeyId || ! -v AliAccessKeySecret ]]; then
|
||||
skip "'AliAccessKeyId' or 'AliAccessKeySecret' environment variable not found"
|
||||
fi
|
||||
test_check_vars() { #@test
|
||||
skip_no_aliaccess
|
||||
|
||||
_AliAccessKeyId=$AliAccessKeyId
|
||||
_AliAccessKeySecret=$AliAccessKeySecret
|
||||
unset AliAccessKeyId AliAccessKeySecret
|
||||
run aliapi_rpc
|
||||
|
||||
run _aliapi_check_vars
|
||||
[[ $status -eq 3 ]]
|
||||
[[ $output == "Aliyun OpenAPI SDK: 'AliAccessKeyId' or 'AliAccessKeySecret' environment variable not found" ]]
|
||||
|
||||
AliAccessKeyId=$_AliAccessKeyId
|
||||
AliAccessKeySecret=$_AliAccessKeySecret
|
||||
|
||||
run _aliapi_check_vars
|
||||
[[ $status -eq 0 ]]
|
||||
}
|
||||
|
||||
test_rpc_api() { #@test
|
||||
skip_no_aliaccess
|
||||
|
||||
run aliapi_rpc GET api.test 0
|
||||
[[ $status -eq 2 ]]
|
||||
[[ $output == "aliapi_rpc: not enough parameters" ]]
|
||||
|
|
Loading…
Reference in New Issue