2016-01-27 02:08:18 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
# `hosts add` #################################################################
|
|
|
|
|
|
|
|
@test "\`add\` with no arguments exits with status 1." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add
|
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 02:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add\` with no argument does not change the hosts file." {
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add\` with no arguments prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]]
|
2016-01-27 02:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts add <ip>` ############################################################
|
|
|
|
|
|
|
|
@test "\`add <ip>\` exits with status 1." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 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 1 ]]
|
2016-01-27 02:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip>\` does not change the hosts file." {
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 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 02:08:18 +00:00
|
|
|
[[ "$(cat "${HOSTS_PATH}")" == "${_original}" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip>\` prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 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 02:08:18 +00:00
|
|
|
[[ "${lines[0]}" == "Please include a hostname" ]]
|
|
|
|
[[ "${lines[1]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[2]}" == " hosts add <ip> <hostname> [<comment>]" ]]
|
2016-01-27 02:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts add <ip> <hostname>` #################################################
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname>\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 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 02:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname>\` adds the entry to the hosts file." {
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
|
|
|
_compare '0.0.0.0 example.com' "$(sed -n '11p' "${HOSTS_PATH}")"
|
|
|
|
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname>\` prints feedback." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
[[ "${lines[0]}" == "Added:" ]]
|
|
|
|
[[ "${lines[1]}" == "0.0.0.0 example.com" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# `hosts add <ip> <hostname> [comment]` #######################################
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname> [comment]\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
|
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:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname> [comment]\` adds the entry to the hosts file." {
|
|
|
|
_original="$(cat "${HOSTS_PATH}")"
|
|
|
|
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
[[ "$(cat "${HOSTS_PATH}")" != "${_original}" ]]
|
|
|
|
[[ "$(sed -n '11p' "${HOSTS_PATH}")" == "0.0.0.0 example.com # Comment." ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`add <ip> <hostname> [comment]\` prints feedback." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" add 0.0.0.0 example.com 'Comment.'
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 02:08:18 +00:00
|
|
|
[[ "${lines[0]}" == "Added:" ]]
|
|
|
|
[[ "${lines[1]}" == "0.0.0.0 example.com # Comment." ]]
|
|
|
|
}
|
2016-01-27 03:01:02 +00:00
|
|
|
|
|
|
|
# help ########################################################################
|
|
|
|
|
|
|
|
@test "\`help add\` exits with status 0." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help add
|
|
|
|
[[ ${status} -eq 0 ]]
|
2016-01-27 03:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "\`help add\` prints help information." {
|
2016-02-24 02:14:21 +00:00
|
|
|
run "${_HOSTS}" help add
|
2018-04-15 21:55:26 +00:00
|
|
|
printf "\${status}: %s\\n" "${status}"
|
|
|
|
printf "\${output}: '%s'\\n" "${output}"
|
2016-01-27 03:01:02 +00:00
|
|
|
[[ "${lines[0]}" == "Usage:" ]]
|
2016-01-27 04:25:16 +00:00
|
|
|
[[ "${lines[1]}" == " hosts add <ip> <hostname> [<comment>]" ]]
|
2016-01-27 03:01:02 +00:00
|
|
|
}
|