ctdb-daemon: Consolidate basic CTDB context initialisation
[samba.git] / testprogs / blackbox / common_test_fns.inc
1 # Common tests
2 # Pulled out of existing tests to prevent duplication.
3 #
4 test_smbclient() {
5         name="$1"
6         cmd="$2"
7         unc="$3"
8         shift
9         shift
10         shift
11         subunit_start_test "$name"
12         output=`$VALGRIND $smbclient $CONFIGURATION "$unc" -c "$cmd" $@ 2>&1`
13         status=$?
14         if [ x$status = x0 ]; then
15                 subunit_pass_test "$name"
16         else
17                 printf '%s' "$output" | subunit_fail_test "$name"
18         fi
19         return $status
20 }
21
22 test_smbclient_expect_failure() {
23         name="$1"
24         cmd="$2"
25         unc="$3"
26         shift
27         shift
28         shift
29         subunit_start_test "$name"
30         output=`$VALGRIND $smbclient $CONFIGURATION "$unc" -c "$cmd" $@ 2>&1`
31         status=$?
32         if [ x$status = x0 ]; then
33                 printf '%s' "$output" | subunit_fail_test "$name"
34         else
35                 subunit_pass_test "$name"
36         fi
37         return $status
38 }
39
40 test_rpcclient_grep() {
41         name="$1"
42         cmd="$2"
43         srv="$3"
44         grep="$4"
45         shift
46         shift
47         shift
48         shift
49         subunit_start_test "$name"
50         output=`$VALGRIND $rpcclient $CONFIGURATION "$srv" -c "$cmd" $@ 2>&1`
51         status=$?
52         if [ x$status != x0 ]; then
53                 printf '%s' "$output" | subunit_fail_test "$name"
54                 return $status
55         fi
56         printf '%s' "$output" | grep -q "$grep"
57         gstatus=$?
58         if [ x$gstatus = x0 ]; then
59                 subunit_pass_test "$name"
60         else
61                 printf '%s' "$output" | subunit_fail_test "$name"
62         fi
63         return $status
64 }
65
66 test_rpcclient_expect_failure_grep() {
67         name="$1"
68         cmd="$2"
69         srv="$3"
70         grep="$4"
71         shift
72         shift
73         shift
74         shift
75         subunit_start_test "$name"
76         output=`$VALGRIND $rpcclient $CONFIGURATION "$srv" -c "$cmd" $@ 2>&1`
77         status=$?
78         if [ x$status = x0 ]; then
79                 printf '%s' "$output" | subunit_fail_test "$name"
80                 return $status
81         fi
82         printf '%s' "$output" | grep -q "$grep"
83         gstatus=$?
84         if [ x$gstatus = x0 ]; then
85                 subunit_pass_test "$name"
86         else
87                 printf '%s' "$output" | subunit_fail_test "$name"
88         fi
89         return $status
90 }
91
92 kerberos_kinit() {
93         kinit_tool="${1}"
94         principal="${2}"
95         password="${3}"
96         shift 3
97         kbase=$(basename ${kinit_tool})
98         if [ "${kbase}" = "samba4kinit" ]; then
99                 kpassfile=$(mktemp)
100                 echo $password > ${kpassfile}
101                 $kinit_tool --password-file=${kpassfile} $principal $@
102                 status=$?
103                 rm -f ${kpassfile}
104         else
105                 echo $password | $kinit_tool $principal $@
106                 status=$?
107         fi
108         return $status
109 }