1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00

tiny-cloud: Print usage on invalid option and add test

Add test that verifies invalid option and `tiny-cloud --help`
This commit is contained in:
Natanael Copa 2023-05-04 11:50:22 +02:00
parent 7ad4565a04
commit 02c0c31703
2 changed files with 21 additions and 2 deletions

View File

@ -21,8 +21,8 @@ bootstrap_incomplete() {
rm -f "$TINY_CLOUD_VAR/.bootstrap-complete"
}
args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@")
if [ $? -ne 0 ] || [ $# -eq 0 ]; then
args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@") || { usage >&2; exit 1; }
if [ $# -eq 0 ]; then
usage >&2
exit 1
fi

19
tests/tiny-cloud.test Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env atf-sh
. $(atf_get_srcdir)/test_env.sh
export PREFIX="$srcdir"
export MOCK=echo
init_tests \
tiny_cloud_help
tiny_cloud_help_body() {
CLOUD=nocloud atf_check -s not-exit:0 \
-e match:"Usage" \
tiny-cloud --invalid
CLOUD=nocloud atf_check -s exit:0 \
-o match:"Usage" \
tiny-cloud --help
}