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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-02-24 02:14:21 +00:00
|
|
|
[[ ${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
|
2018-04-15 21:55:26 +00:00
|
|
|
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
|
2018-04-15 21:55:26 +00:00
|
|
|
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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-02-24 02:14:21 +00:00
|
|
|
[[ ${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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.net ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.net ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "${lines[0]}" == "Disabling:" ]]
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "${lines[1]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-02-24 02:14:21 +00:00
|
|
|
[[ ${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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.net ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ \#disabled\:\ 0.0.0.0[[:space:]]+example.com ]]
|
|
|
|
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 127.0.0.1[[:space:]]+example.com ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:26:49 +00:00
|
|
|
[[ "${lines[0]}" == "Disabling:" ]]
|
2020-04-09 00:27:11 +00:00
|
|
|
[[ "${lines[1]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
2016-01-27 02:26:49 +00:00
|
|
|
}
|
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
|
2018-04-15 21:55:26 +00:00
|
|
|
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
|
|
|
}
|