summaryrefslogtreecommitdiff
path: root/ctdb/tests/cunit/run_event_001.sh
blob: 35c256b6fcd16d5088391eba5f7fa5e50a3f6b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh

. "${TEST_SCRIPTS_DIR}/unit.sh"

# Invalid path
required_result 1 <<EOF
run_event_init() failed, ret=2
EOF
unit_test run_event_test /a/b/c list

scriptdir=$(mktemp -d --tmpdir="$TEST_VAR_DIR")

# Empty directory
ok <<EOF
No event scripts found
EOF
unit_test run_event_test "$scriptdir" list

cat > "$scriptdir/prog" <<EOF
#!/bin/sh

echo hello
EOF

# Invalid script
ok <<EOF
No event scripts found
EOF
unit_test run_event_test "$scriptdir" list

ok <<EOF
Script enable prog completed with result=22
EOF
unit_test run_event_test "$scriptdir" enable prog

required_result 1 <<EOF
EOF
unit_test test -x "${scriptdir}/prog"

cat > "$scriptdir/10.test.rpmnew" <<EOF
#!/bin/sh

echo hello
EOF
chmod +x "$scriptdir/10.test.rpmnew"

# Invalid script with multiple '.'s
ok <<EOF
No event scripts found
EOF
unit_test run_event_test "$scriptdir" list

ok <<EOF
Script disable 10.test.rpmnew completed with result=22
EOF
unit_test run_event_test "$scriptdir" disable 10.test.rpmnew

ok_null
unit_test test -x "${scriptdir}/10.test.rpmnew"

cat > "$scriptdir/11.foo" <<EOF
#!/bin/sh

echo hello
EOF

# Valid script
ok <<EOF
11.foo
EOF
unit_test run_event_test "$scriptdir" list

ok <<EOF
Script enable 11.foo completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 11.foo

ok <<EOF
EOF
unit_test test -x "${scriptdir}/11.foo"

ok <<EOF
11.foo: hello
Event monitor completed with result=0
11.foo result=0
EOF
unit_test run_event_test "$scriptdir" run 10 monitor

cat > "$scriptdir/22.bar" <<EOF
#!/bin/sh

exit 1
EOF

# Multiple scripts
ok <<EOF
11.foo
22.bar
EOF
unit_test run_event_test "$scriptdir" list

ok <<EOF
Script enable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 22.bar

ok <<EOF
11.foo: hello
Event monitor completed with result=1
11.foo result=0
22.bar result=1
EOF
unit_test run_event_test "$scriptdir" run 10 monitor

# Disable script
ok <<EOF
Script disable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" disable 22.bar

required_result 1 <<EOF
EOF
unit_test test -x "${scriptdir}/22.bar"

ok <<EOF
11.foo: hello
Event monitor completed with result=0
11.foo result=0
22.bar result=-8
EOF
unit_test run_event_test "$scriptdir" run 10 monitor

cat > "$scriptdir/22.bar" <<EOF
#!/bin/sh

sleep 10
EOF

# Timed out script
ok <<EOF
Script enable 22.bar completed with result=0
EOF
unit_test run_event_test "$scriptdir" enable 22.bar

ok <<EOF
11.foo: hello
Event monitor completed with result=-62
11.foo result=0
22.bar result=-62
EOF
unit_test run_event_test "$scriptdir" run 5 monitor

rm -rf "$scriptdir"
exit 0