From 30ed049441a9de4820f60486d10f1aa9d595eebc Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 24 Jan 2016 21:05:07 -0800 Subject: [PATCH] Add initial test structure with test 'hosts' file. --- .gitignore | 2 ++ test/fixtures/hosts | 10 ++++++++++ test/hosts.bats | 17 +++++++++++++++++ test/test_helper.bash | 13 +++++++++++++ test/tmp/.keep | 0 5 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 test/fixtures/hosts create mode 100644 test/hosts.bats create mode 100644 test/test_helper.bash create mode 100644 test/tmp/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c0271c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +test/tmp/* +!test/tmp/.keep diff --git a/test/fixtures/hosts b/test/fixtures/hosts new file mode 100644 index 0000000..9c0f7b9 --- /dev/null +++ b/test/fixtures/hosts @@ -0,0 +1,10 @@ +## +# Host Database +# +# localhost is used to configure the loopback interface +# when the system is booting. Do not change this entry. +## +127.0.0.1 localhost +255.255.255.255 broadcasthost +::1 localhost +fe80::1%lo0 localhost diff --git a/test/hosts.bats b/test/hosts.bats new file mode 100644 index 0000000..8dc89e1 --- /dev/null +++ b/test/hosts.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +load test_helper + +@test "when passed no arguments exit with status 0" { + run "$_HOSTS" + [ "$status" -eq 0 ] +} + +@test "when passed no arguments print enabled rules." { + run "$_HOSTS" + [[ "${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]}" == "" ]] +} diff --git a/test/test_helper.bash b/test/test_helper.bash new file mode 100644 index 0000000..e536b5c --- /dev/null +++ b/test/test_helper.bash @@ -0,0 +1,13 @@ +setup() { + # `$_HOSTS` + # + # The location of the `hosts` script being tested. + export _HOSTS="${BATS_TEST_DIRNAME}/../hosts" + + export HOSTS_PATH="${BATS_TEST_DIRNAME}/tmp/hosts" + cp "${BATS_TEST_DIRNAME}/fixtures/hosts" "${BATS_TEST_DIRNAME}/tmp/hosts" +} + +teardown() { + rm "${BATS_TEST_DIRNAME}/tmp/hosts" +} diff --git a/test/tmp/.keep b/test/tmp/.keep new file mode 100644 index 0000000..e69de29