diff --git a/src/tr1d1um/communication.go b/src/tr1d1um/communication.go index 418cd2cb..0a3a3a07 100644 --- a/src/tr1d1um/communication.go +++ b/src/tr1d1um/communication.go @@ -130,14 +130,14 @@ func (tr1 *Tr1SendAndHandle) HandleResponse(err error, respFromServer *http.Resp return } - if RDKResponse, encodingErr := tr1.ExtractPayload(respFromServer.Body, wrp.JSON); encodingErr == nil { + if RDKResponse, encodingErr := tr1.ExtractPayload(respFromServer.Body, wrp.Msgpack); encodingErr == nil { if RDKRespCode, RDKErr := GetStatusCodeFromRDKResponse(RDKResponse); RDKErr == nil && RDKRespCode != http.StatusInternalServerError { tr1Resp.Code = RDKRespCode } tr1Resp.Body = RDKResponse } else { ReportError(encodingErr, tr1Resp) - errorLogger.Log(logging.ErrorKey(), err) + errorLogger.Log(logging.MessageKey(), "could not extract payload from wrp body", logging.ErrorKey(), encodingErr) } ForwardHeadersByPrefix("X", respFromServer, tr1Resp) diff --git a/src/tr1d1um/communication_test.go b/src/tr1d1um/communication_test.go index f9e90503..b3403687 100644 --- a/src/tr1d1um/communication_test.go +++ b/src/tr1d1um/communication_test.go @@ -118,7 +118,7 @@ func TestHandleResponse(t *testing.T) { t.Run("ExtractPayloadFail", func(t *testing.T) { fakeResponse := &http.Response{StatusCode: http.StatusOK} - mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.JSON).Return([]byte(""), + mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.Msgpack).Return([]byte(""), errors.New(errMsg)).Once() recorder := Tr1d1umResponse{}.New() tr1.HandleResponse(nil, fakeResponse, recorder, false) @@ -129,7 +129,7 @@ func TestHandleResponse(t *testing.T) { t.Run("ExtractPayloadTimeout", func(t *testing.T) { fakeResponse := &http.Response{StatusCode: http.StatusOK} - mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.JSON).Return([]byte(""), + mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.Msgpack).Return([]byte(""), context.Canceled).Once() recorder := Tr1d1umResponse{}.New() tr1.HandleResponse(nil, fakeResponse, recorder, false) @@ -150,14 +150,14 @@ func TestHandleResponse(t *testing.T) { assert.EqualValues(http.StatusOK, recorder.Code) assert.EqualValues(bodyString, string(recorder.Body)) - mockEncoding.AssertNotCalled(t, "ExtractPayload", fakeResponse.Body, wrp.JSON) + mockEncoding.AssertNotCalled(t, "ExtractPayload", fakeResponse.Body, wrp.Msgpack) }) t.Run("GoodRDKResponse", func(t *testing.T) { fakeResponse := &http.Response{StatusCode: http.StatusOK} extractedData := []byte(`{"statusCode": 202}`) - mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.JSON).Return(extractedData, nil).Once() + mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.Msgpack).Return(extractedData, nil).Once() recorder := Tr1d1umResponse{}.New() tr1.HandleResponse(nil, fakeResponse, recorder, false) @@ -170,7 +170,7 @@ func TestHandleResponse(t *testing.T) { fakeResponse := &http.Response{StatusCode: http.StatusOK} extractedData := []byte(`{"statusCode": 500}`) - mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.JSON).Return(extractedData, nil).Once() + mockEncoding.On("ExtractPayload", fakeResponse.Body, wrp.Msgpack).Return(extractedData, nil).Once() recorder := Tr1d1umResponse{}.New() tr1.HandleResponse(nil, fakeResponse, recorder, false) diff --git a/src/tr1d1um/retries.go b/src/tr1d1um/retries.go index 12caa440..3212616c 100644 --- a/src/tr1d1um/retries.go +++ b/src/tr1d1um/retries.go @@ -28,8 +28,8 @@ import ( var ( errInvalidMaxRetriesVal = errors.New("retry: MaxRetries should be >= 1") errUndefinedShouldRetry = errors.New("retry: ShouldRetry function is required") - errUndefinedLogger = errors.New("retry: logger is undefined") - errUndefinedRetryOp = errors.New("retry: operation to retry is undefined") + errUndefinedLogger = errors.New("retry: logger is undefined") + errUndefinedRetryOp = errors.New("retry: operation to retry is undefined") ) //RetryStrategy defines @@ -37,7 +37,6 @@ type RetryStrategy interface { Execute(func(...interface{}) (interface{}, error), ...interface{}) (interface{}, error) } - //Retry is the realization of RetryStrategy. It type Retry struct { log.Logger diff --git a/src/tr1d1um/retries_test.go b/src/tr1d1um/retries_test.go index ba705fde..df81aed4 100644 --- a/src/tr1d1um/retries_test.go +++ b/src/tr1d1um/retries_test.go @@ -134,7 +134,7 @@ func TestRetryCheckDependencies(t *testing.T) { retry := Retry{ Interval: time.Second, MaxRetries: 1, - Logger: logging.DefaultLogger(), + Logger: logging.DefaultLogger(), ShouldRetry: func(_ interface{}, _ error) bool { return true }, OnInternalFail: func() interface{} { return -1 diff --git a/src/tr1d1um/tr1d1um_response.go b/src/tr1d1um/tr1d1um_response.go index f1517e1f..042748b9 100644 --- a/src/tr1d1um/tr1d1um_response.go +++ b/src/tr1d1um/tr1d1um_response.go @@ -65,7 +65,6 @@ func WriteResponse(message string, statusCode int, tr1Resp *Tr1d1umResponse) { tr1Resp.Body = []byte(fmt.Sprintf(`{"message":"%s"}`, message)) } - //WriteResponseWriter is a tiny helper function that passes responses (In Json format only for now) //to a caller through a ResponseWriter func WriteResponseWriter(message string, statusCode int, origin http.ResponseWriter) {