Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Nov 21, 2023
1 parent a43bb96 commit f9beaa4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ func checkRedirect(cfg *ResourceConfig, log *logp.Logger) func(*http.Request, []
func retryErrorHandler(max int, log *logp.Logger) retryablehttp.ErrorHandler {
return func(resp *http.Response, err error, numTries int) (*http.Response, error) {
log.Warnw("giving up retries", "method", resp.Request.Method, "url", resp.Request.URL, "retries", max+1)
return resp, nil
return resp, err
}
}

Expand Down
30 changes: 30 additions & 0 deletions x-pack/filebeat/input/cel/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,36 @@ var inputTests = []struct {
{"hello": "world"},
},
},
{
name: "retry_failure_no_success",
server: newTestServer(httptest.NewServer),
config: map[string]interface{}{
"interval": 1,
"resource": map[string]interface{}{
"retry": map[string]interface{}{
"max_attempts": 2,
},
},
"program": `
get(state.url).as(resp, {
"url": state.url,
"events": [
bytes(resp.Body).decode_json(),
{"status": resp.StatusCode},
],
})
`,
},
handler: func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusGatewayTimeout)
w.Write([]byte(`{"error":"we were too slow"}`))
},
want: []map[string]interface{}{
{"error": "we were too slow"},
{"status": float64(504)}, // Float because of JSON.
},
},

{
name: "POST_request",
Expand Down

0 comments on commit f9beaa4

Please sign in to comment.