1272343Sngie# $NetBSD: t_rc_d_cli.sh,v 1.4 2010/11/07 17:51:21 jmmv Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2010 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# This code is derived from software contributed to The NetBSD Foundation
7272343Sngie# by Julio Merino.
8272343Sngie#
9272343Sngie# Redistribution and use in source and binary forms, with or without
10272343Sngie# modification, are permitted provided that the following conditions
11272343Sngie# are met:
12272343Sngie# 1. Redistributions of source code must retain the above copyright
13272343Sngie#    notice, this list of conditions and the following disclaimer.
14272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
15272343Sngie#    notice, this list of conditions and the following disclaimer in the
16272343Sngie#    documentation and/or other materials provided with the distribution.
17272343Sngie#
18272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28272343Sngie# POSSIBILITY OF SUCH DAMAGE.
29272343Sngie#
30272343Sngie
31272343Sngieatf_test_case no_command
32272343Sngieno_command_head() {
33272343Sngie	atf_set "descr" "Tests that the lack of a command errors out"
34272343Sngie}
35272343Sngieno_command_body() {
36272343Sngie	export h_simple=YES
37272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
38272343Sngie
39272343Sngie	atf_check -s eq:1 -o empty -e ignore ${rc_helper}
40272343Sngie}
41272343Sngie
42272343Sngieatf_test_case default_start_no_args
43272343Sngiedefault_start_no_args_head() {
44272343Sngie	atf_set "descr" "Tests that running the default 'start' without" \
45272343Sngie	    "arguments does not error out"
46272343Sngie}
47272343Sngiedefault_start_no_args_body() {
48272343Sngie	export h_simple=YES
49272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
50272343Sngie
51272343Sngie	atf_check -s eq:0 -o ignore -e empty ${rc_helper} start
52272343Sngie	${rc_helper} forcestop
53272343Sngie}
54272343Sngie
55272343Sngieatf_test_case default_start_with_args
56272343Sngiedefault_start_with_args_head() {
57272343Sngie	atf_set "descr" "Tests that running the default 'start' with" \
58272343Sngie	    "arguments errors out"
59272343Sngie}
60272343Sngiedefault_start_with_args_body() {
61272343Sngie	export h_simple=YES
62272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
63272343Sngie
64272343Sngie	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} start foo
65272343Sngie	if ${rc_helper} status >/dev/null; then
66272343Sngie		${rc_helper} forcestop
67272343Sngie		atf_fail 'extra argument to start did not error out'
68272343Sngie	fi
69272343Sngie}
70272343Sngie
71272343Sngieatf_test_case default_stop_no_args
72272343Sngiedefault_stop_no_args_head() {
73272343Sngie	atf_set "descr" "Tests that running the default 'stop' without" \
74272343Sngie	    "arguments does not error out"
75272343Sngie}
76272343Sngiedefault_stop_no_args_body() {
77272343Sngie	export h_simple=YES
78272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
79272343Sngie
80272343Sngie	${rc_helper} start
81272343Sngie	atf_check -s eq:0 -o ignore -e empty ${rc_helper} stop
82272343Sngie}
83272343Sngie
84272343Sngieatf_test_case default_stop_with_args
85272343Sngiedefault_stop_with_args_head() {
86272343Sngie	atf_set "descr" "Tests that running the default 'stop' with" \
87272343Sngie	    "arguments errors out"
88272343Sngie}
89272343Sngiedefault_stop_with_args_body() {
90272343Sngie	export h_simple=YES
91272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
92272343Sngie
93272343Sngie	${rc_helper} start
94272343Sngie	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} stop foo
95272343Sngie	if ${rc_helper} status >/dev/null; then
96272343Sngie		${rc_helper} forcestop
97272343Sngie	else
98272343Sngie		atf_fail 'extra argument to stop did not error out'
99272343Sngie	fi
100272343Sngie}
101272343Sngie
102272343Sngieatf_test_case default_restart_no_args
103272343Sngiedefault_restart_no_args_head() {
104272343Sngie	atf_set "descr" "Tests that running the default 'restart' without" \
105272343Sngie	    "arguments does not error out"
106272343Sngie}
107272343Sngiedefault_restart_no_args_body() {
108272343Sngie	export h_simple=YES
109272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
110272343Sngie
111272343Sngie	${rc_helper} start
112272343Sngie	atf_check -s eq:0 -o ignore -e empty ${rc_helper} restart
113272343Sngie	${rc_helper} forcestop
114272343Sngie}
115272343Sngie
116272343Sngieatf_test_case default_restart_with_args
117272343Sngiedefault_restart_with_args_head() {
118272343Sngie	atf_set "descr" "Tests that running the default 'restart' with" \
119272343Sngie	    "arguments errors out"
120272343Sngie}
121272343Sngiedefault_restart_with_args_body() {
122272343Sngie	export h_simple=YES
123272343Sngie	rc_helper=$(atf_get_srcdir)/h_simple
124272343Sngie
125272343Sngie	${rc_helper} start
126272343Sngie	atf_check -s eq:1 -o ignore -e ignore ${rc_helper} restart foo
127272343Sngie	${rc_helper} forcestop
128272343Sngie}
129272343Sngie
130272343Sngiedo_overriden_no_args() {
131272343Sngie	local command="${1}"; shift
132272343Sngie
133272343Sngie	export h_args=YES
134272343Sngie	rc_helper=$(atf_get_srcdir)/h_args
135272343Sngie
136272343Sngie	cat >expout <<EOF
137272343Sngiepre${command}:.
138272343Sngie${command}:.
139272343Sngiepost${command}:.
140272343SngieEOF
141272343Sngie	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command}
142272343Sngie}
143272343Sngie
144272343Sngiedo_overriden_with_args() {
145272343Sngie	local command="${1}"; shift
146272343Sngie
147272343Sngie	export h_args=YES
148272343Sngie	rc_helper=$(atf_get_srcdir)/h_args
149272343Sngie
150272343Sngie	cat >expout <<EOF
151272343Sngiepre${command}:.
152272343Sngie${command}: >arg1< > arg 2 < >arg3< >*<.
153272343Sngiepost${command}:.
154272343SngieEOF
155272343Sngie	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command} \
156272343Sngie	    'arg1' ' arg 2 ' 'arg3' '*'
157272343Sngie}
158272343Sngie
159272343Sngieatf_test_case overriden_start_no_args
160272343Sngieoverriden_start_no_args_head() {
161272343Sngie	atf_set "descr" "Tests that running a custom 'start' without" \
162272343Sngie	    "arguments does not pass any parameters to the command"
163272343Sngie}
164272343Sngieoverriden_start_no_args_body() {
165272343Sngie	do_overriden_no_args start
166272343Sngie}
167272343Sngie
168272343Sngieatf_test_case overriden_start_with_args
169272343Sngieoverriden_start_with_args_head() {
170272343Sngie	atf_set "descr" "Tests that running a custom 'start' with" \
171272343Sngie	    "arguments passes those arguments as parameters to the command"
172272343Sngie}
173272343Sngieoverriden_start_with_args_body() {
174272343Sngie	do_overriden_with_args start
175272343Sngie}
176272343Sngie
177272343Sngieatf_test_case overriden_stop_no_args
178272343Sngieoverriden_stop_no_args_head() {
179272343Sngie	atf_set "descr" "Tests that running a custom 'stop' without" \
180272343Sngie	    "arguments does not pass any parameters to the command"
181272343Sngie}
182272343Sngieoverriden_stop_no_args_body() {
183272343Sngie	do_overriden_no_args stop
184272343Sngie}
185272343Sngie
186272343Sngieatf_test_case overriden_stop_with_args
187272343Sngieoverriden_stop_with_args_head() {
188272343Sngie	atf_set "descr" "Tests that running a custom 'stop' with" \
189272343Sngie	    "arguments passes those arguments as parameters to the command"
190272343Sngie}
191272343Sngieoverriden_stop_with_args_body() {
192272343Sngie	do_overriden_with_args stop
193272343Sngie}
194272343Sngie
195272343Sngieatf_test_case overriden_restart_no_args
196272343Sngieoverriden_restart_no_args_head() {
197272343Sngie	atf_set "descr" "Tests that running a custom 'restart' without" \
198272343Sngie	    "arguments does not pass any parameters to the command"
199272343Sngie}
200272343Sngieoverriden_restart_no_args_body() {
201272343Sngie	do_overriden_no_args restart
202272343Sngie}
203272343Sngie
204272343Sngieatf_test_case overriden_restart_with_args
205272343Sngieoverriden_restart_with_args_head() {
206272343Sngie	atf_set "descr" "Tests that running a custom 'restart' with" \
207272343Sngie	    "arguments passes those arguments as parameters to the command"
208272343Sngie}
209272343Sngieoverriden_restart_with_args_body() {
210272343Sngie	do_overriden_with_args restart
211272343Sngie}
212272343Sngie
213272343Sngieatf_test_case overriden_custom_no_args
214272343Sngieoverriden_custom_no_args_head() {
215272343Sngie	atf_set "descr" "Tests that running a custom command without" \
216272343Sngie	    "arguments does not pass any parameters to the command"
217272343Sngie}
218272343Sngieoverriden_custom_no_args_body() {
219272343Sngie	do_overriden_no_args custom
220272343Sngie}
221272343Sngie
222272343Sngieatf_test_case overriden_custom_with_args
223272343Sngieoverriden_custom_with_args_head() {
224272343Sngie	atf_set "descr" "Tests that running a custom command with" \
225272343Sngie	    "arguments passes those arguments as parameters to the command"
226272343Sngie}
227272343Sngieoverriden_custom_with_args_body() {
228272343Sngie	do_overriden_with_args custom
229272343Sngie}
230272343Sngie
231272343Sngieatf_init_test_cases()
232272343Sngie{
233272343Sngie	atf_add_test_case no_command
234272343Sngie
235272343Sngie	atf_add_test_case default_start_no_args
236272343Sngie	atf_add_test_case default_start_with_args
237272343Sngie	atf_add_test_case default_stop_no_args
238272343Sngie	atf_add_test_case default_stop_with_args
239272343Sngie	atf_add_test_case default_restart_no_args
240272343Sngie	atf_add_test_case default_restart_with_args
241272343Sngie
242272343Sngie	atf_add_test_case overriden_start_no_args
243272343Sngie	atf_add_test_case overriden_start_with_args
244272343Sngie	atf_add_test_case overriden_stop_no_args
245272343Sngie	atf_add_test_case overriden_stop_with_args
246272343Sngie	atf_add_test_case overriden_restart_no_args
247272343Sngie	atf_add_test_case overriden_restart_with_args
248272343Sngie	atf_add_test_case overriden_custom_no_args
249272343Sngie	atf_add_test_case overriden_custom_with_args
250272343Sngie}
251