Upgrade to latest oparent
[aaf/authz.git] / authz-test / TestSuite / tc
1 #!/bin/bash
2 TS=`echo $0 | sed "s/\/tc//"`
3
4 mkdir -p runs
5
6 function failed {
7      echo "FAILED TEST! $*"
8      exit 1
9 }
10
11 if [ "$1" == "-a" ]; then 
12   OPTS=$OPTS" -a";
13   shift
14 elif [ "$1" == "clean" ]; then 
15   CLEAN="TRUE"
16   shift
17 fi
18
19 if [[ -z $USER ]]; then
20         THE_USER=`whoami`
21 elif [[ -n "$SUDO_USER" ]]; then
22     THE_USER=$SUDO_USER
23 elif [[ -n "$USER" ]]; then
24     THE_USER=$USER
25 fi
26
27 if [ "$1" == "" ]; then
28   DIRS=`find $TS -maxdepth 2 -type d -name "TC_*" | sed "s/^$TS\///" | sort`
29   if [ "$DIRS" == "" ] ; then 
30     echo "Usage: tc <TestCase> [expected]"
31     echo "  expected - create the expected response for future comparison"
32     exit 1
33   fi
34 else
35   DIRS=$1
36   shift
37 fi
38
39 if [ "$1" == "-a" ]; then 
40   OPTS=$OPTS" -a";
41   shift
42 elif [ "$1" == "clean" ]; then 
43   CLEAN="TRUE"
44   shift
45 fi
46
47 if [ -e tc.delay ]; then
48   OPTS=$OPTS" -delayAll "`cat tc.delay`
49 fi
50
51
52 SUFFIX=`date "+%Y-%m-%d_%H:%M:%S"`
53 for TC in $DIRS; do
54   echo $TC
55   if [ "$CLEAN" = "TRUE" ]; then 
56     cat $TS/$TC/00* $TS/$TC/99* | aafcli -i -a -t -n
57     rm -f last
58     ln -s runs/$TC.CLEAN.$SUFFIX last
59   elif [ "$1" = "expected" ]; then
60     SUFFIX=$1
61     cat $TS/$TC/[0-9]* | aafcli -i -t 2>&1 | sed -e "/$THE_USER/s//@[THE_USER]/g" | tee $TS/expected/$TC.$SUFFIX
62   elif [ -d "$TS/$TC" ]; then
63     if [ "$1" = "dryrun" ]; then
64         cat $TS/$TC/[0-9]* > temp
65         cat $TS/$TC/[0-9]* | aafcli -i -t 
66     else 
67         rm -f last
68         > runs/$TC.$SUFFIX
69         ln -s runs/$TC.$SUFFIX last
70         cat $TS/$TC/[0-9]* | aafcli -i -t $OPTS | sed -e "/$THE_USER/s//@[THE_USER]/g" -e "s/\r//"  2>&1 > runs/$TC.$SUFFIX 
71   
72                 diff --ignore-blank-lines -w runs/$TC.$SUFFIX $TS/expected/$TC.expected || failed "[$TC.$SUFFIX]"
73                 echo "SUCCESS! [$TC.$SUFFIX]"
74    fi
75   elif [ -f "$TS/$TC" ]; then
76     cat $TS/$TC | aafcli -i -t $OPTS 
77   else
78     echo missed dir
79   fi
80 done
81
82 exit 0