Skip to content

Commit

Permalink
serve: Fix nc command, test output matching
Browse files Browse the repository at this point in the history
On Linux, `nc` will exit with an error if the hostname argument is
empty. Setting it to `localhost` by default fixes the problem.

On Travis, it appears that file descriptors for standard output and
error still look like terminal file descriptors to Bash, even after
being redirected to a file (i.e. `[[ -t 0 && -t 1 ]]` is always true)`.
This causes the `log` module from `go-script-bash` to always emit
terminal-formatted log labels. This played havoc with the previous
`assert_output_matches` assertions, which only checked for whitespace
between log label text and the log message text. The fix was to update
each assertion so that all log labels are immediately followed by `.* `.
  • Loading branch information
mbland committed Aug 19, 2017
1 parent 599800f commit e68f097
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion scripts/serve
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cl.serve_launch_redis() {
}

cl.serve_wait_for_redis() {
local redis_host="$1"
local redis_host="${1:-localhost}"
local redis_pid="$2"
local timeout="${CUSTOM_LINKS_REDIS_TIMEOUT:-5}"

Expand Down
27 changes: 13 additions & 14 deletions tests/scripts/serve.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ setup() {
export CUSTOM_LINKS_REDIS_DIR="${BATS_TEST_ROOTDIR}/redis-test"
export CUSTOM_LINKS_REDIS_LOG_PATH="${CUSTOM_LINKS_REDIS_DIR}/redis.log"

export _GO_LOG_FORMATTING=
create_bats_test_dirs 'redis-test'
create_config_file
}
Expand Down Expand Up @@ -173,10 +172,10 @@ stop_background_run() {
fail 'Append only file not created'
fi

assert_output_matches 'INFO +redis-server running'
assert_output_matches 'INFO +custom-links server shutdown complete'
assert_output_matches 'RUN +Shutting down redis-server'
assert_output_matches 'INFO +redis-server shutdown complete'
assert_output_matches 'INFO.* redis-server running'
assert_output_matches 'INFO.* custom-links server shutdown complete'
assert_output_matches 'RUN.* Shutting down redis-server'
assert_output_matches 'INFO.* redis-server shutdown complete'
}

@test "$SUITE: launches redis-server in background from config file" {
Expand All @@ -190,8 +189,8 @@ stop_background_run() {
wait_for_background_output "custom-links listening on port $CUSTOM_LINKS_PORT"
stop_background_run

assert_output_matches 'INFO +custom-links server shutdown complete'
assert_output_matches 'INFO +redis-server shutdown complete'
assert_output_matches 'INFO.* custom-links server shutdown complete'
assert_output_matches 'INFO.* redis-server shutdown complete'
}

@test "$SUITE: uses redis-server that's already running" {
Expand All @@ -200,10 +199,10 @@ stop_background_run() {
wait_for_background_output "custom-links listening on port $CUSTOM_LINKS_PORT"
stop_background_run

fail_if output_matches 'INFO +redis-server running'
assert_output_matches 'INFO +custom-links server shutdown complete'
fail_if output_matches 'RUN +Shutting down redis-server'
fail_if output_matches 'INFO +redis-server shutdown complete'
fail_if output_matches 'INFO.* redis-server running'
assert_output_matches 'INFO.* custom-links server shutdown complete'
fail_if output_matches 'RUN.* Shutting down redis-server'
fail_if output_matches 'INFO.* redis-server shutdown complete'
}

@test "$SUITE: waits for redis-server on another host" {
Expand All @@ -215,14 +214,14 @@ stop_background_run() {
wait_for_background_output "custom-links listening on port $CUSTOM_LINKS_PORT"
stop_background_run

fail_if output_matches 'INFO +redis-server running'
assert_output_matches 'INFO +custom-links server shutdown complete'
fail_if output_matches 'INFO.* redis-server running'
assert_output_matches 'INFO.* custom-links server shutdown complete'
}

@test "$SUITE: error when redis-server launch fails" {
stub_program_in_path 'redis-server' 'exit 1'
CUSTOM_LINKS_REDIS_TIMEOUT='0' run_in_background ./go serve
wait_for_background_output "FATAL +Failed to launch redis-server"
wait_for_background_output "FATAL.* Failed to launch redis-server"
restore_program_in_path 'redis-server'
stop_background_run
assert_failure
Expand Down

0 comments on commit e68f097

Please sign in to comment.