mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-28 15:56:33 +00:00
Add tests for duplicate entry guard.
Deplicate entries are avoided by a guard in the `add` subcommand. Add tests to ensure that duplicate entries are not created.
This commit is contained in:
parent
a475dc53aa
commit
6b72e51651
@ -84,6 +84,23 @@ load test_helper
|
||||
[[ "${lines[1]}" == "0.0.0.0 example.com" ]]
|
||||
}
|
||||
|
||||
@test "\`add <ip> <hostname>\` doesn't add duplicate entry." {
|
||||
_original="$(cat "${HOSTS_PATH}")"
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
}
|
||||
_modified="$(cat "${HOSTS_PATH}")"
|
||||
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
||||
_compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
|
||||
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
|
||||
[[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]]
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]]
|
||||
}
|
||||
|
||||
# `hosts add <ip> <hostname> [comment]` #######################################
|
||||
|
||||
@test "\`add <ip> <hostname> [comment]\` exits with status 0." {
|
||||
@ -104,6 +121,43 @@ load test_helper
|
||||
"0.0.0.0 example.com # Example multi-word comment." ]]
|
||||
}
|
||||
|
||||
@test "\`add <ip> <hostname> [comment]\` doesn't add duplicate entry." {
|
||||
_original="$(cat "${HOSTS_PATH}")"
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
}
|
||||
_modified="$(cat "${HOSTS_PATH}")"
|
||||
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
||||
_compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
|
||||
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
|
||||
[[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]]
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]]
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" != \
|
||||
"0.0.0.0 example.com # Example multi-word comment." ]]
|
||||
}
|
||||
|
||||
@test "\`add <ip> <hostname> [comment]\` doesn't add duplicate commented entry." {
|
||||
_original="$(cat "${HOSTS_PATH}")"
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
|
||||
}
|
||||
_modified="$(cat "${HOSTS_PATH}")"
|
||||
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
||||
_compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
|
||||
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
|
||||
[[ "$(cat "${HOSTS_PATH}")" == "${_modified}" ]]
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == \
|
||||
"0.0.0.0 example.com # Example multi-word comment." ]]
|
||||
}
|
||||
|
||||
@test "\`add <ip> <hostname> [comment]\` prints feedback." {
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com 'Example multi-word comment.'
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
|
Loading…
Reference in New Issue
Block a user