Skip to content

Commit e68f097

Browse files
committed
serve: Fix nc command, test output matching
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 `.* `.
1 parent 599800f commit e68f097

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

scripts/serve

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cl.serve_launch_redis() {
8080
}
8181

8282
cl.serve_wait_for_redis() {
83-
local redis_host="$1"
83+
local redis_host="${1:-localhost}"
8484
local redis_pid="$2"
8585
local timeout="${CUSTOM_LINKS_REDIS_TIMEOUT:-5}"
8686

tests/scripts/serve.bats

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ setup() {
1616
export CUSTOM_LINKS_REDIS_DIR="${BATS_TEST_ROOTDIR}/redis-test"
1717
export CUSTOM_LINKS_REDIS_LOG_PATH="${CUSTOM_LINKS_REDIS_DIR}/redis.log"
1818

19-
export _GO_LOG_FORMATTING=
2019
create_bats_test_dirs 'redis-test'
2120
create_config_file
2221
}
@@ -173,10 +172,10 @@ stop_background_run() {
173172
fail 'Append only file not created'
174173
fi
175174

176-
assert_output_matches 'INFO +redis-server running'
177-
assert_output_matches 'INFO +custom-links server shutdown complete'
178-
assert_output_matches 'RUN +Shutting down redis-server'
179-
assert_output_matches 'INFO +redis-server shutdown complete'
175+
assert_output_matches 'INFO.* redis-server running'
176+
assert_output_matches 'INFO.* custom-links server shutdown complete'
177+
assert_output_matches 'RUN.* Shutting down redis-server'
178+
assert_output_matches 'INFO.* redis-server shutdown complete'
180179
}
181180

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

193-
assert_output_matches 'INFO +custom-links server shutdown complete'
194-
assert_output_matches 'INFO +redis-server shutdown complete'
192+
assert_output_matches 'INFO.* custom-links server shutdown complete'
193+
assert_output_matches 'INFO.* redis-server shutdown complete'
195194
}
196195

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

203-
fail_if output_matches 'INFO +redis-server running'
204-
assert_output_matches 'INFO +custom-links server shutdown complete'
205-
fail_if output_matches 'RUN +Shutting down redis-server'
206-
fail_if output_matches 'INFO +redis-server shutdown complete'
202+
fail_if output_matches 'INFO.* redis-server running'
203+
assert_output_matches 'INFO.* custom-links server shutdown complete'
204+
fail_if output_matches 'RUN.* Shutting down redis-server'
205+
fail_if output_matches 'INFO.* redis-server shutdown complete'
207206
}
208207

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

218-
fail_if output_matches 'INFO +redis-server running'
219-
assert_output_matches 'INFO +custom-links server shutdown complete'
217+
fail_if output_matches 'INFO.* redis-server running'
218+
assert_output_matches 'INFO.* custom-links server shutdown complete'
220219
}
221220

222221
@test "$SUITE: error when redis-server launch fails" {
223222
stub_program_in_path 'redis-server' 'exit 1'
224223
CUSTOM_LINKS_REDIS_TIMEOUT='0' run_in_background ./go serve
225-
wait_for_background_output "FATAL +Failed to launch redis-server"
224+
wait_for_background_output "FATAL.* Failed to launch redis-server"
226225
restore_program_in_path 'redis-server'
227226
stop_background_run
228227
assert_failure

0 commit comments

Comments
 (0)