xref: /freebsd/contrib/netbsd-tests/sys/rc/t_rc_d_cli.sh (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1# $NetBSD: t_rc_d_cli.sh,v 1.4 2010/11/07 17:51:21 jmmv Exp $
2#
3# Copyright (c) 2010 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# This code is derived from software contributed to The NetBSD Foundation
7# by Julio Merino.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31atf_test_case no_command
32no_command_head() {
33	atf_set "descr" "Tests that the lack of a command errors out"
34}
35no_command_body() {
36	export h_simple=YES
37	rc_helper=$(atf_get_srcdir)/h_simple
38
39	atf_check -s eq:1 -o empty -e ignore ${rc_helper}
40}
41
42atf_test_case default_start_no_args
43default_start_no_args_head() {
44	atf_set "descr" "Tests that running the default 'start' without" \
45	    "arguments does not error out"
46}
47default_start_no_args_body() {
48	export h_simple=YES
49	rc_helper=$(atf_get_srcdir)/h_simple
50
51	atf_check -s eq:0 -o ignore -e empty ${rc_helper} start
52	${rc_helper} forcestop
53}
54
55atf_test_case default_start_with_args
56default_start_with_args_head() {
57	atf_set "descr" "Tests that running the default 'start' with" \
58	    "arguments errors out"
59}
60default_start_with_args_body() {
61	export h_simple=YES
62	rc_helper=$(atf_get_srcdir)/h_simple
63
64	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} start foo
65	if ${rc_helper} status >/dev/null; then
66		${rc_helper} forcestop
67		atf_fail 'extra argument to start did not error out'
68	fi
69}
70
71atf_test_case default_stop_no_args
72default_stop_no_args_head() {
73	atf_set "descr" "Tests that running the default 'stop' without" \
74	    "arguments does not error out"
75}
76default_stop_no_args_body() {
77	export h_simple=YES
78	rc_helper=$(atf_get_srcdir)/h_simple
79
80	${rc_helper} start
81	atf_check -s eq:0 -o ignore -e empty ${rc_helper} stop
82}
83
84atf_test_case default_stop_with_args
85default_stop_with_args_head() {
86	atf_set "descr" "Tests that running the default 'stop' with" \
87	    "arguments errors out"
88}
89default_stop_with_args_body() {
90	export h_simple=YES
91	rc_helper=$(atf_get_srcdir)/h_simple
92
93	${rc_helper} start
94	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} stop foo
95	if ${rc_helper} status >/dev/null; then
96		${rc_helper} forcestop
97	else
98		atf_fail 'extra argument to stop did not error out'
99	fi
100}
101
102atf_test_case default_restart_no_args
103default_restart_no_args_head() {
104	atf_set "descr" "Tests that running the default 'restart' without" \
105	    "arguments does not error out"
106}
107default_restart_no_args_body() {
108	export h_simple=YES
109	rc_helper=$(atf_get_srcdir)/h_simple
110
111	${rc_helper} start
112	atf_check -s eq:0 -o ignore -e empty ${rc_helper} restart
113	${rc_helper} forcestop
114}
115
116atf_test_case default_restart_with_args
117default_restart_with_args_head() {
118	atf_set "descr" "Tests that running the default 'restart' with" \
119	    "arguments errors out"
120}
121default_restart_with_args_body() {
122	export h_simple=YES
123	rc_helper=$(atf_get_srcdir)/h_simple
124
125	${rc_helper} start
126	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} restart foo
127	${rc_helper} forcestop
128}
129
130do_overriden_no_args() {
131	local command="${1}"; shift
132
133	export h_args=YES
134	rc_helper=$(atf_get_srcdir)/h_args
135
136	cat >expout <<EOF
137pre${command}:.
138${command}:.
139post${command}:.
140EOF
141	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command}
142}
143
144do_overriden_with_args() {
145	local command="${1}"; shift
146
147	export h_args=YES
148	rc_helper=$(atf_get_srcdir)/h_args
149
150	cat >expout <<EOF
151pre${command}:.
152${command}: >arg1< > arg 2 < >arg3< >*<.
153post${command}:.
154EOF
155	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command} \
156	    'arg1' ' arg 2 ' 'arg3' '*'
157}
158
159atf_test_case overriden_start_no_args
160overriden_start_no_args_head() {
161	atf_set "descr" "Tests that running a custom 'start' without" \
162	    "arguments does not pass any parameters to the command"
163}
164overriden_start_no_args_body() {
165	do_overriden_no_args start
166}
167
168atf_test_case overriden_start_with_args
169overriden_start_with_args_head() {
170	atf_set "descr" "Tests that running a custom 'start' with" \
171	    "arguments passes those arguments as parameters to the command"
172}
173overriden_start_with_args_body() {
174	do_overriden_with_args start
175}
176
177atf_test_case overriden_stop_no_args
178overriden_stop_no_args_head() {
179	atf_set "descr" "Tests that running a custom 'stop' without" \
180	    "arguments does not pass any parameters to the command"
181}
182overriden_stop_no_args_body() {
183	do_overriden_no_args stop
184}
185
186atf_test_case overriden_stop_with_args
187overriden_stop_with_args_head() {
188	atf_set "descr" "Tests that running a custom 'stop' with" \
189	    "arguments passes those arguments as parameters to the command"
190}
191overriden_stop_with_args_body() {
192	do_overriden_with_args stop
193}
194
195atf_test_case overriden_restart_no_args
196overriden_restart_no_args_head() {
197	atf_set "descr" "Tests that running a custom 'restart' without" \
198	    "arguments does not pass any parameters to the command"
199}
200overriden_restart_no_args_body() {
201	do_overriden_no_args restart
202}
203
204atf_test_case overriden_restart_with_args
205overriden_restart_with_args_head() {
206	atf_set "descr" "Tests that running a custom 'restart' with" \
207	    "arguments passes those arguments as parameters to the command"
208}
209overriden_restart_with_args_body() {
210	do_overriden_with_args restart
211}
212
213atf_test_case overriden_custom_no_args
214overriden_custom_no_args_head() {
215	atf_set "descr" "Tests that running a custom command without" \
216	    "arguments does not pass any parameters to the command"
217}
218overriden_custom_no_args_body() {
219	do_overriden_no_args custom
220}
221
222atf_test_case overriden_custom_with_args
223overriden_custom_with_args_head() {
224	atf_set "descr" "Tests that running a custom command with" \
225	    "arguments passes those arguments as parameters to the command"
226}
227overriden_custom_with_args_body() {
228	do_overriden_with_args custom
229}
230
231atf_init_test_cases()
232{
233	atf_add_test_case no_command
234
235	atf_add_test_case default_start_no_args
236	atf_add_test_case default_start_with_args
237	atf_add_test_case default_stop_no_args
238	atf_add_test_case default_stop_with_args
239	atf_add_test_case default_restart_no_args
240	atf_add_test_case default_restart_with_args
241
242	atf_add_test_case overriden_start_no_args
243	atf_add_test_case overriden_start_with_args
244	atf_add_test_case overriden_stop_no_args
245	atf_add_test_case overriden_stop_with_args
246	atf_add_test_case overriden_restart_no_args
247	atf_add_test_case overriden_restart_with_args
248	atf_add_test_case overriden_custom_no_args
249	atf_add_test_case overriden_custom_with_args
250}
251