diff --git a/services/streammanager/googlecloudfunction/googlecloudfunction.go b/services/streammanager/googlecloudfunction/googlecloudfunction.go index 5950ec2cca..0b8ff5c381 100644 --- a/services/streammanager/googlecloudfunction/googlecloudfunction.go +++ b/services/streammanager/googlecloudfunction/googlecloudfunction.go @@ -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 diff --git a/services/streammanager/googlecloudfunction/googlecloudfunction_test.go b/services/streammanager/googlecloudfunction/googlecloudfunction_test.go index ed519c4d11..23b5ffca10 100644 --- a/services/streammanager/googlecloudfunction/googlecloudfunction_test.go +++ b/services/streammanager/googlecloudfunction/googlecloudfunction_test.go @@ -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)