Home | History | Annotate | Line # | Download | only in rc
t_rc_d_cli.sh revision 1.4
      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 
     31 atf_test_case no_command
     32 no_command_head() {
     33 	atf_set "descr" "Tests that the lack of a command errors out"
     34 }
     35 no_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 
     42 atf_test_case default_start_no_args
     43 default_start_no_args_head() {
     44 	atf_set "descr" "Tests that running the default 'start' without" \
     45 	    "arguments does not error out"
     46 }
     47 default_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 
     55 atf_test_case default_start_with_args
     56 default_start_with_args_head() {
     57 	atf_set "descr" "Tests that running the default 'start' with" \
     58 	    "arguments errors out"
     59 }
     60 default_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 
     71 atf_test_case default_stop_no_args
     72 default_stop_no_args_head() {
     73 	atf_set "descr" "Tests that running the default 'stop' without" \
     74 	    "arguments does not error out"
     75 }
     76 default_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 
     84 atf_test_case default_stop_with_args
     85 default_stop_with_args_head() {
     86 	atf_set "descr" "Tests that running the default 'stop' with" \
     87 	    "arguments errors out"
     88 }
     89 default_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 
    102 atf_test_case default_restart_no_args
    103 default_restart_no_args_head() {
    104 	atf_set "descr" "Tests that running the default 'restart' without" \
    105 	    "arguments does not error out"
    106 }
    107 default_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 
    116 atf_test_case default_restart_with_args
    117 default_restart_with_args_head() {
    118 	atf_set "descr" "Tests that running the default 'restart' with" \
    119 	    "arguments errors out"
    120 }
    121 default_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 
    130 do_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
    137 pre${command}:.
    138 ${command}:.
    139 post${command}:.
    140 EOF
    141 	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command}
    142 }
    143 
    144 do_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
    151 pre${command}:.
    152 ${command}: >arg1< > arg 2 < >arg3< >*<.
    153 post${command}:.
    154 EOF
    155 	atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command} \
    156 	    'arg1' ' arg 2 ' 'arg3' '*'
    157 }
    158 
    159 atf_test_case overriden_start_no_args
    160 overriden_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 }
    164 overriden_start_no_args_body() {
    165 	do_overriden_no_args start
    166 }
    167 
    168 atf_test_case overriden_start_with_args
    169 overriden_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 }
    173 overriden_start_with_args_body() {
    174 	do_overriden_with_args start
    175 }
    176 
    177 atf_test_case overriden_stop_no_args
    178 overriden_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 }
    182 overriden_stop_no_args_body() {
    183 	do_overriden_no_args stop
    184 }
    185 
    186 atf_test_case overriden_stop_with_args
    187 overriden_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 }
    191 overriden_stop_with_args_body() {
    192 	do_overriden_with_args stop
    193 }
    194 
    195 atf_test_case overriden_restart_no_args
    196 overriden_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 }
    200 overriden_restart_no_args_body() {
    201 	do_overriden_no_args restart
    202 }
    203 
    204 atf_test_case overriden_restart_with_args
    205 overriden_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 }
    209 overriden_restart_with_args_body() {
    210 	do_overriden_with_args restart
    211 }
    212 
    213 atf_test_case overriden_custom_no_args
    214 overriden_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 }
    218 overriden_custom_no_args_body() {
    219 	do_overriden_no_args custom
    220 }
    221 
    222 atf_test_case overriden_custom_with_args
    223 overriden_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 }
    227 overriden_custom_with_args_body() {
    228 	do_overriden_with_args custom
    229 }
    230 
    231 atf_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