Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge error blocks in gcf #4004

Merged
merged 11 commits into from
Oct 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ func (producer *GoogleCloudFunctionProducer) Produce(jsonData json.RawMessage, _

// Make the request using the client
resp, err := producer.httpClient.Do(req)
if err != nil && os.IsTimeout(err) {
return http.StatusAccepted, "Success", "[GoogleCloudFunction] :: Function is called"
}

var responseBody []byte

if err == nil {
defer func() { httputil.CloseResponse(resp) }()
responseBody, err = io.ReadAll(resp.Body)
}

if err != nil {
if os.IsTimeout(err) {
return http.StatusAccepted, "Success", "[GoogleCloudFunction] :: Function is called"
}
responseMessage = err.Error()
respStatus = "Failure"
responseMessage = "[GOOGLE_CLOUD_FUNCTION] error :: Function call was not executed " + responseMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func TestConfigGenerateToken(t *testing.T) {
assert.NotNil(t, err)
}

func TestNewProduceWithBadServer(t *testing.T) {
ctrl := gomock.NewController(t)
mockClient := mock_googlecloudfunction.NewMockGoogleCloudFunctionClient(ctrl)
conf := &Config{
RequireAuthentication: false,
FunctionUrl: "http://rudderstack-non-existing-server:54321",
}
producer := &GoogleCloudFunctionProducer{client: mockClient, config: conf, httpClient: http.DefaultClient}
statusCode, responseStatus, responseMessage := producer.Produce([]byte("invalid_json"), map[string]string{})
assert.Equal(t, http.StatusBadRequest, statusCode)
assert.Equal(t, "Failure", responseStatus)
assert.Contains(t, responseMessage, "Function call was not executed")
}

func TestNewProduceWithInvalidData(t *testing.T) {
testSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Bad Request", http.StatusBadRequest)
Expand Down
Loading