1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-11 07:40:56 +00:00
hosts/test/show.bats
William Melody 187222614a Use braces in all variable references.
Braces are only required in certain cases, but the cognitive overhead in
keeping track of which cases require braces can be reduced by simply
always using them.

Example: `${NAME}`

Retain more widely-used braces `$NAME` convention in documentation.
2016-02-23 18:14:21 -08:00

100 lines
2.8 KiB
Bash

#!/usr/bin/env bats
load test_helper
# `hosts show` ##############################################################
@test "\`show\` with no arguments exits with status 1." {
run "${_HOSTS}" show
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ ${status} -eq 1 ]]
}
@test "\`show\` with no arguments prints help information." {
run "${_HOSTS}" show
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
}
# `hosts show <ip>` #########################################################
@test "\`show <ip>\` 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 example.com
}
run "${_HOSTS}" show 0.0.0.0
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ ${status} -eq 0 ]]
}
@test "\`enable <ip>\` shows all matches." {
{
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
}
run "${_HOSTS}" show 0.0.0.0
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ "${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." {
{
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}" show example.com
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ ${status} -eq 0 ]]
}
@test "\`enable <hostname>\` shows all matches." {
{
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}" show example.com
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ "${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." {
run "${_HOSTS}" help show
[[ ${status} -eq 0 ]]
}
@test "\`help show\` prints help information." {
run "${_HOSTS}" help show
printf "\${status}: %s\n" "${status}"
printf "\${output}: '%s'\n" "${output}"
[[ "${lines[0]}" == "Usage:" ]]
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
}