#!/bin/sh SCRIPTNAME="$( dirname $0)/check_dns_quickcheck_fullresolv.sh" TESTNAME="Test with no domain" EXPECTED_OUTPUT='OK \(no domains tested\)' EXPECTED_EXIT_STATUS=0 OUTPUT="$( $SCRIPTNAME 2>&1 )" if [ "$?" -ne "$EXPECTED_EXIT_STATUS" ]; then echo "ERROR: $TESTNAME exit code = $? (instead of $EXPECTED_EXIT_STATUS)"; exit; fi if [ "$( echo "$OUTPUT" | egrep -c "$EXPECTED_OUTPUT" 2>&1 )" != "1" ]; then echo "ERROR: $TESTNAME outputs '$OUTPUT' (instead of '$EXPECTED_OUTPUT')"; exit 1; fi TESTNAME="Test with one existent domain" EXPECTED_OUTPUT='^OK www\.example\.net|'t_www\.example\.net'=[0-9]+ms;;;0$' EXPECTED_EXIT_STATUS=0 OUTPUT="$( $SCRIPTNAME -d www.example.net 2>&1 )" if [ "$?" -ne "$EXPECTED_EXIT_STATUS" ]; then echo "ERROR: $TESTNAME exit code = $? (instead of $EXPECTED_EXIT_STATUS)"; exit; fi if [ "$( echo "$OUTPUT" | egrep -c "$EXPECTED_OUTPUT" 2>&1 )" != "1" ]; then echo "ERROR: $TESTNAME outputs '$OUTPUT' (instead of '$EXPECTED_OUTPUT')"; exit 1; fi TESTNAME="Test with one existent domain (ending with a '.')" EXPECTED_OUTPUT='^OK www\.example\.net\.|'t_www\.example\.net'=[0-9]+ms;;;0$' EXPECTED_EXIT_STATUS=0 OUTPUT="$( $SCRIPTNAME -d www.example.net. 2>&1 )" if [ "$?" -ne "$EXPECTED_EXIT_STATUS" ]; then echo "ERROR: $TESTNAME exit code = $? (instead of $EXPECTED_EXIT_STATUS)"; exit; fi if [ "$( echo "$OUTPUT" | egrep -c "$EXPECTED_OUTPUT" 2>&1 )" != "1" ]; then echo "ERROR: $TESTNAME outputs '$OUTPUT' (instead of '$EXPECTED_OUTPUT')"; exit 1; fi TESTNAME="Test with two existent domains" EXPECTED_OUTPUT='^OK www\.example\.net www\.example\.org|'t_www\.example\.net'=[0-9]+ms;;;0 't_www\.example\.org.'=[0-9]+ms;;;0$' EXPECTED_EXIT_STATUS=0 OUTPUT="$( $SCRIPTNAME -d www.example.net -d www.example.org. 2>&1 )" if [ "$?" -ne "$EXPECTED_EXIT_STATUS" ]; then echo "ERROR: $TESTNAME exit code = $? (instead of $EXPECTED_EXIT_STATUS)"; exit; fi if [ "$( echo "$OUTPUT" | egrep -c "$EXPECTED_OUTPUT" 2>&1 )" != "1" ]; then echo "ERROR: $TESTNAME outputs '$OUTPUT' (instead of '$EXPECTED_OUTPUT')"; exit 1; fi TESTNAME="Test with one existent and one inexistent domain" EXPECTED_OUTPUT='^CRITICAL inexistent\.example\.net$' EXPECTED_EXIT_STATUS=2 OUTPUT="$( $SCRIPTNAME -d www.example.net -d inexistent.example.net 2>&1 )" if [ "$?" -ne "$EXPECTED_EXIT_STATUS" ]; then echo "ERROR: $TESTNAME exit code = $? (instead of $EXPECTED_EXIT_STATUS)"; exit; fi if [ "$( echo "$OUTPUT" | egrep -c "$EXPECTED_OUTPUT" 2>&1 )" != "1" ]; then echo "ERROR: $TESTNAME outputs '$OUTPUT' (instead of '$EXPECTED_OUTPUT')"; exit 1; fi # TODO: test timeout # TODO: test logger