diff options
author | xxc3nsoredxx <xxc3ncoredxx@gmail.com> | 2021-05-07 16:11:11 -0500 |
---|---|---|
committer | Rasmus Thomsen <oss@cogitri.dev> | 2021-06-01 14:25:32 +0200 |
commit | a0e24dc668842004a0c57ca022e6eb07b666b537 (patch) | |
tree | 625e9d58b2ae6245197244f05bacbf8955a226be | |
parent | 19fc72c7cdaf8eda2838b3ce1fdf2526db866c19 (diff) | |
download | wgetpaste-a0e24dc668842004a0c57ca022e6eb07b666b537.tar.gz |
Differentiate between skips
Slightly different behavior based on if it's a hard skip, auth skip, or
post/download failure skip. HARD_SKIPS array to control which services
are always skipped. Add total skips and fail logs to summary.
-rwxr-xr-x | test/test.sh | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/test/test.sh b/test/test.sh index 52e305d..fa4abc2 100755 --- a/test/test.sh +++ b/test/test.sh @@ -8,6 +8,12 @@ TEST_DIR="$(dirname "$0")" TEST_FILE="$TEST_DIR/test.txt" DL_DIR="$(mktemp -q -d /tmp/wgetpaste_test.XXXXX)" +# Services to hard skip +# codepad: timing out +HARD_SKIPS=('codepad') +HARD_SKIP_COUNT=0 +AUTH_SKIP_COUNT=0 +FAIL_SKIP_COUNT=0 DL_COUNT=0 DL_MISMATCH=0 @@ -20,31 +26,48 @@ echo "Using download directory: $DL_DIR" # Post test file into each service (if possible) # Download the resulting paste into /tmp/wgetpaste_test.XXXXX/<service>.txt -for s in $("$TEST_DIR"/../wgetpaste -S --completions); do - # Ignore codepad (timing out) - if [ "$s" == 'codepad' ]; then - continue - fi +for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do + # Hard skips + for hs in "${HARD_SKIPS[@]}"; do + if [ "$serv" == "$hs" ]; then + echo "HARD SKIP on $serv..." + HARD_SKIP_COUNT=$((HARD_SKIP_COUNT + 1)) + continue 2 + fi + done - # Discard stderr output - echo -n "Posting to $s: " - URL="$("$TEST_DIR"/../wgetpaste -r -s "$s" "$TEST_FILE" 2>/dev/null)" + # Log errors to analyze the reason + # Use verbose output to get more meaningful errors + # Log deleted at the end of each loop unless error other than 401 + echo -n "Posting to $serv: " + ERROR_LOG="$DL_DIR/$serv-error.log" + URL="$("$TEST_DIR"/../wgetpaste -r -s "$serv" -v "$TEST_FILE" 2>"$ERROR_LOG")" STATUS="$?" - # Skip failed posts (eg, not authorized for GitHub or GitLab) + # Skip failed posts (eg, not authorized for GitHub/GitLab, service error) if [ "$STATUS" -ne 0 ]; then - echo "FAILED, skipping..." + if (grep -iq "HTTP.*401.*Unauthorized" "$ERROR_LOG"); then + echo "SKIPPING, needs authorization..." + AUTH_SKIP_COUNT=$((AUTH_SKIP_COUNT + 1)) + rm "$ERROR_LOG" + else + echo "SKIPPING, failed to post..." + FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1)) + fi + continue fi echo "SUCCESS!" - echo -n "Downloading from $s: " - if ! (wget -q "$URL" -O "$DL_DIR/$s.txt" 2>/dev/null); then + echo -n "Downloading from $serv: " + if ! (wget -q "$URL" -O "$DL_DIR/$serv.txt" 2>>"$ERROR_LOG"); then echo "FAILED, skipping..." + FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1)) continue fi echo "SUCCESS!" DL_COUNT=$((DL_COUNT + 1)) + rm "$ERROR_LOG" done # Test if any files were downloaded @@ -55,10 +78,10 @@ if [ "$DL_COUNT" -eq 0 ]; then fi # Compare downloaded files -for f in "$DL_DIR"/*; do - echo -n "Testing file $f: " +for dl_file in "$DL_DIR"/*; do + echo -n "Testing file $dl_file: " # Ignore missing trailing newline in downloaded file - if ! (diff -q -Z "$TEST_FILE" "$f" &>/dev/null); then + if ! (diff -q -Z "$TEST_FILE" "$dl_file" &>/dev/null); then echo "FAILED!" DL_MISMATCH=$((DL_MISMATCH + 1)) else @@ -67,6 +90,15 @@ for f in "$DL_DIR"/*; do done echo "Total mismatches: $DL_MISMATCH" +echo "Total skips: $((HARD_SKIP_COUNT + AUTH_SKIP_COUNT + FAIL_SKIP_COUNT))" + +# Print non-auth failure logs +if [ "$FAIL_SKIP_COUNT" -ne 0 ]; then + for log in "$DL_DIR"/*.log; do + echo "$(basename "$log"):" + cat "$log" + done +fi # Delete download directory if all tests succeeded if [ "$DL_MISMATCH" -eq 0 ]; then |