diff options
| author | mo <mo.khan@gmail.com> | 2019-05-25 19:26:35 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-05-25 19:26:35 -0600 |
| commit | 3b353f1d1f778798fa5a232fd29ef5dd1ce5b8f1 (patch) | |
| tree | 300aaa4c6c98cdfa3be149bf5ed3980ff9119508 | |
| parent | 46ca1dabb41b6e1500f379380fb674b292d7230c (diff) | |
add a test for the hostname parameter
| -rwxr-xr-x | bin/problem-7.sh | 5 | ||||
| -rw-r--r-- | test/problem-7.bats | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/bin/problem-7.sh b/bin/problem-7.sh index 1005ac3..4e53180 100755 --- a/bin/problem-7.sh +++ b/bin/problem-7.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ $# -eq 0 ]; then + echo "error: a hostname is required" >&2 + exit 1 +fi + destination="$1" host=$(host "$1" | grep 'has address') ip=$(echo "$host" | cut -d' ' -f4) diff --git a/test/problem-7.bats b/test/problem-7.bats index 57d657a..6b5e193 100644 --- a/test/problem-7.bats +++ b/test/problem-7.bats @@ -13,3 +13,9 @@ load test_helper assert_success "unknown is NOT on the network" } + +@test "invoke without a hostname argument" { + run problem-7.sh + + assert_failure "error: a hostname is required" +} |
