1# $NetBSD: t_rc_d_cli.sh,v 1.3 2010/06/04 08:39:41 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 atf_set "use.fs" "true" 164} 165overriden_start_no_args_body() { 166 do_overriden_no_args start 167} 168 169atf_test_case overriden_start_with_args 170overriden_start_with_args_head() { 171 atf_set "descr" "Tests that running a custom 'start' with" \ 172 "arguments passes those arguments as parameters to the command" 173 atf_set "use.fs" "true" 174} 175overriden_start_with_args_body() { 176 do_overriden_with_args start 177} 178 179atf_test_case overriden_stop_no_args 180overriden_stop_no_args_head() { 181 atf_set "descr" "Tests that running a custom 'stop' without" \ 182 "arguments does not pass any parameters to the command" 183 atf_set "use.fs" "true" 184} 185overriden_stop_no_args_body() { 186 do_overriden_no_args stop 187} 188 189atf_test_case overriden_stop_with_args 190overriden_stop_with_args_head() { 191 atf_set "descr" "Tests that running a custom 'stop' with" \ 192 "arguments passes those arguments as parameters to the command" 193 atf_set "use.fs" "true" 194} 195overriden_stop_with_args_body() { 196 do_overriden_with_args stop 197} 198 199atf_test_case overriden_restart_no_args 200overriden_restart_no_args_head() { 201 atf_set "descr" "Tests that running a custom 'restart' without" \ 202 "arguments does not pass any parameters to the command" 203 atf_set "use.fs" "true" 204} 205overriden_restart_no_args_body() { 206 do_overriden_no_args restart 207} 208 209atf_test_case overriden_restart_with_args 210overriden_restart_with_args_head() { 211 atf_set "descr" "Tests that running a custom 'restart' with" \ 212 "arguments passes those arguments as parameters to the command" 213 atf_set "use.fs" "true" 214} 215overriden_restart_with_args_body() { 216 do_overriden_with_args restart 217} 218 219atf_test_case overriden_custom_no_args 220overriden_custom_no_args_head() { 221 atf_set "descr" "Tests that running a custom command without" \ 222 "arguments does not pass any parameters to the command" 223 atf_set "use.fs" "true" 224} 225overriden_custom_no_args_body() { 226 do_overriden_no_args custom 227} 228 229atf_test_case overriden_custom_with_args 230overriden_custom_with_args_head() { 231 atf_set "descr" "Tests that running a custom command with" \ 232 "arguments passes those arguments as parameters to the command" 233 atf_set "use.fs" "true" 234} 235overriden_custom_with_args_body() { 236 do_overriden_with_args custom 237} 238 239atf_init_test_cases() 240{ 241 atf_add_test_case no_command 242 243 atf_add_test_case default_start_no_args 244 atf_add_test_case default_start_with_args 245 atf_add_test_case default_stop_no_args 246 atf_add_test_case default_stop_with_args 247 atf_add_test_case default_restart_no_args 248 atf_add_test_case default_restart_with_args 249 250 atf_add_test_case overriden_start_no_args 251 atf_add_test_case overriden_start_with_args 252 atf_add_test_case overriden_stop_no_args 253 atf_add_test_case overriden_stop_with_args 254 atf_add_test_case overriden_restart_no_args 255 atf_add_test_case overriden_restart_with_args 256 atf_add_test_case overriden_custom_no_args 257 atf_add_test_case overriden_custom_with_args 258} 259