2016-01-27 02:58:32 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
# `hosts list` #############################################################
|
|
|
|
|
|
|
|
@test "\`list\` 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 02:58:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list
|
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:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`list\` prints lists of enabled and disabled records." {
|
|
|
|
{
|
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 02:58:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:58:32 +00:00
|
|
|
_expected="\
|
|
|
|
127.0.0.1 localhost
|
|
|
|
255.255.255.255 broadcasthost
|
|
|
|
::1 localhost
|
|
|
|
fe80::1%lo0 localhost
|
|
|
|
127.0.0.2 example.com
|
|
|
|
|
|
|
|
Disabled:
|
|
|
|
0.0.0.0 example.com
|
|
|
|
0.0.0.0 example.net"
|
2016-02-24 02:14:21 +00:00
|
|
|
_compare "'${_expected}'" "'${output}'"
|
|
|
|
[[ "${output}" == "${_expected}" ]]
|
2016-01-27 02:58:32 +00:00
|
|
|
}
|
2016-01-27 03:00:02 +00:00
|
|
|
|
2016-01-27 04:15:10 +00:00
|
|
|
# `hosts list enabled` ########################################################
|
|
|
|
|
|
|
|
@test "\`list enabled\` 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 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list enabled
|
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 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`list enabled\` prints list of enabled records." {
|
|
|
|
{
|
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 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list enabled
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 04:15:10 +00:00
|
|
|
[[ "${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]}" == "127.0.0.2 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts list disabled` #######################################################
|
|
|
|
|
|
|
|
@test "\`list disabled\` 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.1 example.com
|
|
|
|
run "${_HOSTS}" disable example.com
|
2016-01-27 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-01 20:47:49 +00:00
|
|
|
run "${_HOSTS}" list disabled
|
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 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`list disabled\` prints list of disabled records." {
|
|
|
|
{
|
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.1 example.com
|
|
|
|
run "${_HOSTS}" disable example.com
|
2016-01-27 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list disabled
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 04:15:10 +00:00
|
|
|
[[ "${lines[0]}" == "0.0.0.0 example.com" ]]
|
|
|
|
[[ "${lines[1]}" == "127.0.0.1 example.com" ]]
|
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts list <search string>` ################################################
|
|
|
|
|
|
|
|
@test "\`list <search string>\` 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.1 example.com
|
2016-01-27 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list 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 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`list <search string>\` prints list of matching records." {
|
|
|
|
{
|
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.1 example.com
|
2016-01-27 04:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" list example.com
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 04:15:10 +00:00
|
|
|
[[ "${lines[0]}" == "0.0.0.0 example.com" ]]
|
|
|
|
[[ "${lines[1]}" == "127.0.0.1 example.com" ]]
|
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:27:06 +00:00
|
|
|
@test "\`list <search string>\` prints records with matching comments." {
|
2018-08-14 18:14:55 +00:00
|
|
|
{
|
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.com
|
|
|
|
}
|
|
|
|
|
|
|
|
run "${_HOSTS}" list "Comment"
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
|
|
|
[[ "${lines[0]}" == "0.0.0.0 example.net # Example Comment" ]]
|
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:27:06 +00:00
|
|
|
|
|
|
|
@test "\`list <search string>\` prints disabled records with matching comments." {
|
|
|
|
{
|
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.com
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.biz "Example Comment"
|
|
|
|
run "${_HOSTS}" disable example.biz
|
|
|
|
}
|
|
|
|
|
|
|
|
run "${_HOSTS}" list "Comment"
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
|
|
|
[[ "${lines[0]}" == "0.0.0.0 example.net # Example Comment" ]]
|
|
|
|
[[ "${lines[1]}" == "disabled: 127.0.0.1 example.biz # Example Comment" ]]
|
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
2016-01-27 03:00:02 +00:00
|
|
|
# help ########################################################################
|
|
|
|
|
|
|
|
@test "\`help list\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help list
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 03:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`help list\` prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help list
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 03:00:02 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
|
|
|
[[ "${lines[1]}" == " hosts list [enabled | disabled | <search string>]" ]]
|
|
|
|
}
|