Subversion Repositories vgwhois

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
#!/bin/bash
2
 
3
#
4
#  generic Whois - Maintenance Framework: Testcases
5
#
6
#  (c) 2012-2014 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de]
7
#
8
#  Distribution, usage etc. pp. regulated by the current version of GPL.
9
#
10
#
11
#  Version 2014-08-25
12
#
13
 
14
DIR=$( dirname "$0" )
15
 
4 daniel-mar 16
TESTCASES_LIST="$DIR/../../config/testcases.list"
17
 
2 daniel-mar 18
# ---
19
 
20
function FileAge() {
21
	echo $((`date +%s` - `stat -c %Y $1`))
22
}
23
 
24
function HumanReadableAge() {
25
	local seconds=$1
26
	local days=$(($seconds/86400))
27
	seconds=$(($seconds-($days*86400) ))
28
	local hours=$(($seconds/3600))
29
	seconds=$((seconds-($hours*3600) ))
30
	local minutes=$(($seconds/60))
31
	seconds=$(( $seconds-($minutes*60) ))
32
 
33
	# echo -n "${days}D ${hours}H ${minutes}M ${seconds}S"
34
	if [ $days -gt 0 ]; then
35
		if [ $hours -gt 12 ]; then
36
			((days++));
37
		fi
38
		echo -n "${days} days ago"
39
	elif [ $hours -gt 0 ]; then
40
		if [ $minutes -gt 30 ]; then
41
			((hours++));
42
		fi
43
		echo -n "${hours} hours ago"
44
	elif [ $minutes -gt 0 ]; then
45
		if [ $seconds -gt 30 ]; then
46
			((minutes++));
47
		fi
48
		echo -n "${minutes} minutes ago"
49
	else
50
		echo -n "a few seconds ago"
51
	fi
52
}
53
 
54
# ---
55
 
56
. "$DIR/../../config/testcases.conf"
57
 
4 daniel-mar 58
CACHE_DIR="$DIR/../../.cache"
59
 
2 daniel-mar 60
echo "Query                          Last activity        Status"
61
echo "----------------------------------------------------------------------------------"
62
 
63
while read f; do
64
	if [ -z "$f" ]; then
65
		continue;
66
	fi
67
 
68
	# Check if the line begins with an '#' (leading spaces are permitted)
69
	echo "$f" | grep -E "\s*^#" > /dev/null
70
	if [ $? -eq 0 ]; then
71
		continue;
72
	fi
73
 
74
	# Warum? "tld jp" wird dann zu "tld"
75
	# query="$( basename $f )"
76
	query="$f";
77
 
4 daniel-mar 78
	if [ ! -d "$CACHE_DIR/testcases/expected" ]; then
79
		mkdir -p "$CACHE_DIR/testcases/expected"
3 daniel-mar 80
	fi
4 daniel-mar 81
	expfile="$CACHE_DIR/testcases/expected/$query"
2 daniel-mar 82
 
4 daniel-mar 83
	if [ ! -d "$CACHE_DIR/testcases/checktimestamps" ]; then
84
		mkdir -p "$CACHE_DIR/testcases/checktimestamps"
3 daniel-mar 85
	fi
4 daniel-mar 86
	tsfile="$CACHE_DIR/testcases/checktimestamps/$query"
2 daniel-mar 87
	if [ -f "$tsfile" ]; then
88
		# lastcheck="$( date -r "$tsfile" )"
89
		lastcheck=$( HumanReadableAge $( FileAge "$tsfile" ))
90
	else
91
		lastcheck="never"
92
	fi
93
 
4 daniel-mar 94
	if [ ! -d "$CACHE_DIR/testcases/problems" ]; then
95
		mkdir -p "$CACHE_DIR/testcases/problems"
3 daniel-mar 96
	fi
4 daniel-mar 97
	errfile="$CACHE_DIR/testcases/problems/$query"
2 daniel-mar 98
	if [ -f "$errfile" ]; then
99
		cat "$errfile" | grep -E "at /(bin|usr|etc|var)/\S+ line" > /dev/null
100
		PERLERR=$?
101
 
102
		cat "$errfile" | head -n 1 | grep -E "^("$'\xEF\xBB\xBF'"){0,1}Process query: '$query'" > /dev/null
103
		STARTEXP=$?
104
 
105
		cat "$errfile" | grep "gwhois remarks: If this is a valid domainname or handle, please file a bug report." > /dev/null
106
		NOPATTERNMATCH=$?
107
 
108
		if [ $PERLERR -eq 0 ]; then
109
			status="Perl-Error!"
110
		elif [ $STARTEXP -ne 0 ]; then
111
			status="Unexpected head line"
112
		elif [ $NOPATTERNMATCH -eq 0 ]; then
113
			status="No pattern match"
114
		elif [ -f "$expfile" ]; then
115
			status="Different output"
116
		else
117
			status="No expected output defined"
118
		fi
119
	else
120
		if [ -f "$expfile" ]; then
121
			status="OK"
122
		else
123
			status="No expected output defined"
124
		fi
125
	fi
126
 
127
	if [ ! -f "$tsfile" ] || [ $( stat --format=%Y "$tsfile" ) -le $(( $( date +%s ) - $recheck_time )) ]; then
128
		if [ ! -f "$errfile" ] || [ $( stat --format=%Y "$errfile" ) -le $(( $( date +%s ) - $recheck_time )) ]; then
129
			status="$status, outdated"
130
		fi
131
	fi
132
 
133
	printf "%-30s %-20s %-20s\n" "$query" "$lastcheck" "$status"
4 daniel-mar 134
done < "$TESTCASES_LIST"