2016-01-27 03:15:14 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
2020-05-17 18:33:57 +00:00
|
|
|
# `hosts show` ################################################################
|
2016-01-27 03:15:14 +00:00
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
2020-04-22 18:53:40 +00:00
|
|
|
# `hosts show <no matching>` ##################################################
|
|
|
|
|
|
|
|
@test "\`show <query>\` with no matching records with status 1." {
|
|
|
|
{
|
|
|
|
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 bad-query
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
|
|
|
[[ ${status} -eq 1 ]]
|
|
|
|
|
|
|
|
[[ "${lines[0]}" =~ No\ matching\ entries ]]
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:33:57 +00:00
|
|
|
# `hosts show <ip>` ###########################################################
|
2016-01-27 03:15:14 +00:00
|
|
|
|
2020-04-08 23:43:07 +00:00
|
|
|
@test "\`show <ip>\` exits with status 0 and shows all matches." {
|
2016-01-27 03:15:14 +00:00
|
|
|
{
|
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
|
|
|
|
2020-04-08 23:43:07 +00:00
|
|
|
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example.net ]]
|
|
|
|
[[ "${lines[3]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts show <hostname>` #####################################################
|
|
|
|
|
2020-04-08 23:43:07 +00:00
|
|
|
@test "\`show <hostname>\` exits with status 0 and shows all matches." {
|
2016-01-27 03:15:14 +00:00
|
|
|
{
|
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
|
|
|
|
2020-04-08 23:43:07 +00:00
|
|
|
[[ "${lines[0]}" =~ 127\.0\.0\.2[[:space:]]+example.com ]]
|
2020-05-17 18:33:57 +00:00
|
|
|
[[ "${lines[3]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
2016-01-27 03:15:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 18:14:55 +00:00
|
|
|
# `hosts show <search string>` ################################################
|
|
|
|
|
2020-04-08 23:43:07 +00:00
|
|
|
@test "\`show <search string>\` exits with status 0 and shows matching records." {
|
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
|
|
|
|
run "${_HOSTS}" add 127.0.0.1 example.com
|
|
|
|
}
|
|
|
|
|
|
|
|
run "${_HOSTS}" show example.com
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
|
|
|
[[ ${status} -eq 0 ]]
|
|
|
|
|
2020-05-17 18:33:57 +00:00
|
|
|
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
2020-04-08 23:43:07 +00:00
|
|
|
[[ "${lines[1]}" =~ 127\.0\.0\.1[[:space:]]+example.com ]]
|
2018-08-14 18:14:55 +00:00
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:27:06 +00:00
|
|
|
@test "\`show <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}" show "Comment"
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2020-04-08 23:43:07 +00:00
|
|
|
printf "\${lines[0]}: '%s'\\n" "${lines[0]}"
|
|
|
|
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example\.net[[:space:]]+\#\ Example\ Comment ]]
|
2018-08-14 18:14:55 +00:00
|
|
|
[[ "${lines[2]}" == "" ]]
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:27:06 +00:00
|
|
|
@test "\`show <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}" show "Comment"
|
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2020-05-17 18:33:57 +00:00
|
|
|
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example\.net[[:space:]]+\#\ Example\ Comment ]]
|
|
|
|
[[ "${lines[3]}" =~ 127\.0\.0\.1[[:space:]]+example\.biz[[:space:]]+\#\ Example\ Comment ]]
|
2020-04-08 23:43:07 +00:00
|
|
|
[[ "${lines[4]}" == "" ]]
|
2018-08-14 18:27:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 03:15:14 +00:00
|
|
|
# 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
|
|
|
}
|