From eb57a685c49e68e31f8a572dc27a812f3e05ffef Mon Sep 17 00:00:00 2001 From: William Melody Date: Tue, 26 Jan 2016 20:15:10 -0800 Subject: [PATCH] Expand list.bats. --- test/list.bats | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/test/list.bats b/test/list.bats index 7842280..a069b71 100644 --- a/test/list.bats +++ b/test/list.bats @@ -43,6 +43,102 @@ Disabled: [[ "$output" == "$_expected" ]] } +# `hosts list enabled` ######################################################## + +@test "\`list enabled\` exits with status 0." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.2 example.com + run "$_HOSTS" disable 0.0.0.0 + } + + run "$_HOSTS" list enabled + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ $status -eq 0 ]] +} + +@test "\`list enabled\` prints list of enabled records." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.2 example.com + run "$_HOSTS" disable 0.0.0.0 + } + + run "$_HOSTS" list enabled + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ "${lines[0]}" == "127.0.0.1 localhost" ]] + [[ "${lines[1]}" == "255.255.255.255 broadcasthost" ]] + [[ "${lines[2]}" == "::1 localhost" ]] + [[ "${lines[3]}" == "fe80::1%lo0 localhost" ]] + [[ "${lines[4]}" == "127.0.0.2 example.com" ]] +} + +# `hosts list disabled` ####################################################### + +@test "\`list disabled\` exits with status 0." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.1 example.com + run "$_HOSTS" disable example.com + } + + run "$_HOSTS" disabled + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ $status -eq 0 ]] +} + +@test "\`list disabled\` prints list of disabled records." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.1 example.com + run "$_HOSTS" disable example.com + } + + run "$_HOSTS" list disabled + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ "${lines[0]}" == "0.0.0.0 example.com" ]] + [[ "${lines[1]}" == "127.0.0.1 example.com" ]] + [[ "${lines[2]}" == "" ]] +} + +# `hosts list ` ################################################ + +@test "\`list \` exits with status 0." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.1 example.com + } + + run "$_HOSTS" list example.com + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ $status -eq 0 ]] +} + +@test "\`list \` prints list of matching records." { + { + run "$_HOSTS" add 0.0.0.0 example.com + run "$_HOSTS" add 0.0.0.0 example.net + run "$_HOSTS" add 127.0.0.1 example.com + } + + run "$_HOSTS" list example.com + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ "${lines[0]}" == "0.0.0.0 example.com" ]] + [[ "${lines[1]}" == "127.0.0.1 example.com" ]] + [[ "${lines[2]}" == "" ]] +} + # help ######################################################################## @test "\`help list\` exits with status 0." {