Skip to content

Commit f32f319

Browse files
committed
Test: more curl-ing - detect http status code
1 parent 76b87eb commit f32f319

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: spec/integration/outputs/index_spec.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,24 @@
6161
let(:curl_opts) { nil }
6262

6363
def curl_and_get_json_response(url, method: :get); require 'open3'
64+
cmd = "curl -s -v --show-error #{curl_opts} -X #{method.to_s.upcase} -k #{url}"
6465
begin
65-
stdout, status = Open3.capture2("curl -s --show-error #{curl_opts} -X #{method.to_s.upcase} -k #{url}")
66+
out, err, status = Open3.capture3(cmd)
6667
rescue Errno::ENOENT
6768
fail "curl not available, make sure curl binary is installed and available on $PATH"
6869
end
6970

7071
if status.success?
71-
LogStash::Json.load(stdout)
72+
http_status = err.match(/< HTTP\/1.1 (.*?)/)[1] || '0' # < HTTP/1.1 200 OK\r\n
73+
if http_status.strip[0].to_i > 2
74+
warn out
75+
fail "#{cmd.inspect} unexpected response: #{http_status}\n\n#{err}"
76+
end
77+
78+
LogStash::Json.load(out)
7279
else
73-
fail "curl failed: #{status}\n #{stdout}"
80+
warn out
81+
fail "#{cmd.inspect} process failed: #{status}\n\n#{err}"
7482
end
7583
end
7684

0 commit comments

Comments
 (0)