From 09c375633f373509e595cce032a343a25947493d Mon Sep 17 00:00:00 2001 From: William Melody Date: Tue, 26 Jan 2016 18:58:32 -0800 Subject: [PATCH] Add list.bats. --- test/list.bats | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/list.bats diff --git a/test/list.bats b/test/list.bats new file mode 100644 index 0000000..fd352bd --- /dev/null +++ b/test/list.bats @@ -0,0 +1,44 @@ +#!/usr/bin/env bats + +load test_helper + +# `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.2 example.com + run "$_HOSTS" disable 0.0.0.0 + } + + run "$_HOSTS" list + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + [[ $status -eq 0 ]] +} + +@test "\`list\` prints lists of enabled and 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.2 example.com + run "$_HOSTS" disable 0.0.0.0 + } + + run "$_HOSTS" list + printf "\$status: %s\n" "$status" + printf "\$output: '%s'\n" "$output" + _expected="\ +127.0.0.1 localhost +255.255.255.255 broadcasthost +::1 localhost +fe80::1%lo0 localhost +127.0.0.2 example.com + +Disabled: +0.0.0.0 example.com +0.0.0.0 example.net" + _compare "'$_expected'" "'$output'" + [[ "$output" == "$_expected" ]] +}