2016-01-27 03:15:14 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
# `hosts show` ##############################################################
|
|
|
|
|
|
|
|
@test "\`show\` with no arguments exits with status 1." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show
|
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 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`show\` with no arguments prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 03:15:14 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts show <ip>` #########################################################
|
|
|
|
|
|
|
|
@test "\`show <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 0.0.0.0 example.net
|
|
|
|
run "${_HOSTS}" add 127.0.0.2 example.com
|
|
|
|
run "${_HOSTS}" disable example.com
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show 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 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`enable <ip>\` shows 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
|
|
|
|
run "${_HOSTS}" add 127.0.0.2 example.com
|
|
|
|
run "${_HOSTS}" disable example.com
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show 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 03:15:14 +00:00
|
|
|
|
|
|
|
[[ "${lines[0]}" == "0.0.0.0 example.net" ]]
|
|
|
|
[[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts show <hostname>` #####################################################
|
|
|
|
|
|
|
|
@test "\`show <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 0.0.0.0 example.net
|
|
|
|
run "${_HOSTS}" add 127.0.0.2 example.com
|
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show 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 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`enable <hostname>\` shows 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
|
|
|
|
run "${_HOSTS}" add 127.0.0.2 example.com
|
|
|
|
run "${_HOSTS}" disable 0.0.0.0
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" show example.com
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 03:15:14 +00:00
|
|
|
|
|
|
|
[[ "${lines[0]}" == "127.0.0.2 example.com" ]]
|
|
|
|
[[ "${lines[1]}" == "disabled: 0.0.0.0 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# help ########################################################################
|
|
|
|
|
|
|
|
@test "\`help show\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help show
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`help show\` prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help show
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 03:15:14 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|