Browse Source

Check github limits when testing --upgrade usage

test_newline_change
Tim Kimber 3 years ago
parent
commit
eba59c535f
No known key found for this signature in database GPG Key ID: 3E1804964E76BD18
3 changed files with 40 additions and 32 deletions
  1. +3
    -0
      test/0-test-usage.bats
  2. +0
    -32
      test/32-test-upgrade.bats
  3. +37
    -0
      test/test_helper.bash

+ 3
- 0
test/0-test-usage.bats View File

@ -40,6 +40,9 @@ setup() {
if [ -n "$STAGING" ]; then
skip "Using staging server, skipping internal test"
fi
# Feb-23 Getting semi-repeatable "can't check for upgrades: ''" errors which are because the limit is being exceeded (re-use of github action ip?)
check_github_quota 7
run ${CODE_DIR}/getssl --upgrade
refute_output
assert_success


+ 0
- 32
test/32-test-upgrade.bats View File

@ -4,38 +4,6 @@ load '/bats-support/load.bash'
load '/bats-assert/load.bash'
load '/getssl/test/test_helper.bash'
LIMIT_API="https://api.github.com/rate_limit"
# Quota generally shouldn't be an issue - except for tests
# Rate limits are per-IP address
check_github_quota() {
local need remaining reset limits now
need="$1"
while true ; do
limits="$(curl ${_NOMETER:---silent} --user-agent "$CURL_USERAGENT" -H 'Accept: application/vnd.github.v3+json' "$LIMIT_API")"
errcode=$?
if [[ $errcode -eq 60 ]]; then
error_exit "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
elif [[ $errcode -gt 0 ]]; then
error_exit "curl error checking releases: $errcode"
fi
remaining="$(jq -r '.resources.core.remaining' <<<"$limits")"
reset="$(jq -r '.resources.core.reset' <<<"$limits")"
if [[ "$remaining" -ge "$need" ]] ; then return 0 ; fi
limit="$(jq -r '.resources.core.limit' <<<"$limits")"
if [[ "$limit" -lt "$need" ]] ; then
error_exit "GitHub API request $need exceeds limit $limit"
fi
now="$(date +%s)"
while [[ "$now" -lt "$reset" ]] ; do
info "sleeping $(( "$reset" - "$now" )) seconds for GitHub quota"
sleep "$(( "$reset" - "$now" ))"
now="$(date +%s)"
done
done
}
setup_file() {
if [ -n "$STAGING" ]; then
echo "Using staging server, skipping internal test" >&3


+ 37
- 0
test/test_helper.bash View File

@ -1,5 +1,6 @@
INSTALL_DIR=/root
CODE_DIR=/getssl
LIMIT_API="https://api.github.com/rate_limit"
check_certificates()
{
@ -8,6 +9,42 @@ check_certificates()
assert [ -e "${INSTALL_DIR}/.getssl/${GETSSL_CMD_HOST}/${GETSSL_CMD_HOST}.crt" ]
}
# Quota generally shouldn't be an issue - except for tests
# Rate limits are per-IP address
check_github_quota() {
local need remaining reset limits now
need="$1"
echo "# Checking github limits"
while true ; do
limits="$(curl ${_NOMETER:---silent} --user-agent "srvrco/getssl/github-actions" -H 'Accept: application/vnd.github.v3+json' "$LIMIT_API")"
echo "# limits = $limits"
errcode=$?
if [[ $errcode -eq 60 ]]; then
echo "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
exit 1
elif [[ $errcode -gt 0 ]]; then
echo "curl error checking releases: $errcode"
exit 1
fi
remaining="$(jq -r '.resources.core.remaining' <<<"$limits")"
echo "# Remaining: $remaining"
reset="$(jq -r '.resources.core.reset' <<<"$limits")"
if [[ "$remaining" -ge "$need" ]] ; then return 0 ; fi
limit="$(jq -r '.resources.core.limit' <<<"$limits")"
echo "# Limit: $limit"
if [[ "$limit" -lt "$need" ]] ; then
echo "GitHub API request $need exceeds limit $limit"
exit 1
fi
now="$(date +%s)"
while [[ "$now" -lt "$reset" ]] ; do
echo "# sleeping $(( "$reset" - "$now" )) seconds for GitHub quota"
sleep "$(( "$reset" - "$now" ))"
now="$(date +%s)"
done
done
}
# Only nginx > 1.11.0 support dual certificates in a single configuration file
# https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script
check_nginx() {


Loading…
Cancel
Save