2016-01-27 02:26:49 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
# `hosts disable` #############################################################
|
|
|
|
|
|
|
|
@test "\`disable\` with no arguments exits with status 1." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
|
|
|
[[ ${status} -eq 1 ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable\` with no argument does not change the hosts file." {
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable\` with no arguments prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts disable <ip>` ########################################################
|
|
|
|
|
|
|
|
@test "\`disable <ip>\` exits with status 0." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <ip>\` updates the hosts file." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <ip>\` disables all matches." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.net" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <ip>\` prints feedback." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "${lines[0]}" == "Disabling:" ]]
|
|
|
|
[[ "${lines[1]}" == "0.0.0.0 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts disable <hostname>` ##################################################
|
|
|
|
|
|
|
|
@test "\`disable <hostname>\` exits with status 0." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable example.com
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <hostname>\` updates the hosts file." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable example.com
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "127.0.0.1 example.net" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <hostname>\` disables all matches." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.com
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable example.com
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "#disabled: 0.0.0.0 example.com" ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" == "#disabled: 127.0.0.1 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`disable <hostname>\` prints feedback." {
|
|
|
|
{
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.net
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" disable example.com
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "${lines[0]}" == "Disabling:" ]]
|
|
|
|
[[ "${lines[1]}" == "0.0.0.0 example.com" ]]
|
|
|
|
}
|
2016-01-27 03:02:07 +00:00
|
|
|
|
|
|
|
# help ########################################################################
|
|
|
|
|
|
|
|
@test "\`help disable\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help disable
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 03:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`help disable\` prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help disable
|
|
|
|
printf "\${status}: %s\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\n" "${output}"
|
2016-01-27 03:02:07 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts disable (<ip> | <hostname> | <search string>)" ]]
|
2016-01-27 03:02:07 +00:00
|
|
|
}
|