summaryrefslogtreecommitdiff
path: root/test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test.sh')
-rwxr-xr-xtest.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..ef0206c
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+TITLE="Service Tests"
+HOME="/home/ist"
+TESTDIR="$HOME/service-tests"
+
+. $HOME/.bashrc
+
+DATE=`date +%y%m%d`
+separator="============================"
+
+LOGDIR="$HOME/log"
+ERRLOG="$LOGDIR/$DATE-err.log"
+LOG="$LOGDIR/$DATE.log"
+MSG="$HOME/msg.log"
+rm "$LOG" 2>/dev/null
+rm "$ERRLOG" 2>/dev/null
+rm "$MSG" 2>/dev/null
+
+touch $LOG
+touch $ERRLOG
+touch $MSG
+
+cd $TESTDIR
+tests=(service-tests.rb)
+for t in ${tests[@]}; do
+ echo $separator | tee -a $LOG $MSG
+ echo " "$t|tr [a-z] [A-Z] | tee -a $LOG $MSG
+ echo " "`date` | tee -a $LOG $MSG
+ echo $separator | tee -a $LOG $MSG
+ echo ruby $t | tee -a $LOG $MSG
+ # whole test output to logfile only
+ ruby $t >> $LOG
+ # take last occurrence of regex to end of the file
+ awk '/^Finished in/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' $LOG >> $MSG
+ echo "" >> $LOG
+done
+
+# MAIL
+file="$HOME/scripts/recipients"
+recipients=$(cat $file)
+if grep -q "Error:" $LOG; then ERRMSG=" ERROR (`grep -c ' Error:' $LOG`)"; else ERRMSG=" OK "; fi
+if grep -q "Failure:" $LOG; then FAILMSG=" FAIL (`grep -c ' Failure:' $LOG`)"; else FAILMSG=""; fi
+
+for p in ${recipients[@]}; do
+ #{ printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $MSG; } | msmtp -a default $p
+ { printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $LOG; } | msmtp -a default $p
+done
+
+exit 0