@@ -3,6 +3,7 @@ package quobyte
33import (
44 "bytes"
55 "encoding/json"
6+ "fmt"
67 "net/http"
78 "net/http/httptest"
89 "reflect"
@@ -62,7 +63,7 @@ func TestSuccessfullDecodeResponse(t *testing.T) {
6263 res , _ := json .Marshal (expectedResult )
6364
6465 var resp CreateVolumeResponse
65- err := decodeResponse (bytes .NewReader (res ), & resp )
66+ err := decodeResponse ("" , bytes .NewReader (res ), & resp )
6667 if err != nil {
6768 t .Log (err )
6869 t .Fail ()
@@ -75,7 +76,8 @@ func TestSuccessfullDecodeResponse(t *testing.T) {
7576}
7677
7778func TestSuccessfullDecodeResponseWithErrorMessage (t * testing.T ) {
78- errorMessage := "ERROR_CODE_INVALID_REQUEST"
79+ method := "testMethod"
80+ errorMessage := fmt .Sprintf (errorMessageFormat , method , "ERROR_CODE_INVALID_REQUEST" )
7981 var byt json.RawMessage
8082 byt , _ = json .Marshal (& rpcError {
8183 Code : - 32600 ,
@@ -91,7 +93,7 @@ func TestSuccessfullDecodeResponseWithErrorMessage(t *testing.T) {
9193 res , _ := json .Marshal (expectedResult )
9294
9395 var resp CreateVolumeResponse
94- err := decodeResponse (bytes .NewReader (res ), & resp )
96+ err := decodeResponse (method , bytes .NewReader (res ), & resp )
9597 if err == nil {
9698 t .Log ("No error occurred" )
9799 t .Fail ()
@@ -104,7 +106,8 @@ func TestSuccessfullDecodeResponseWithErrorMessage(t *testing.T) {
104106}
105107
106108func TestSuccesfullDecodeResponseWithErrorCode (t * testing.T ) {
107- errorMessage := "ERROR_CODE_INVALID_REQUEST"
109+ method := "testMethod"
110+ errorMessage := fmt .Sprintf (errorMessageFormat , method , "ERROR_CODE_INVALID_REQUEST" )
108111 var byt json.RawMessage
109112 byt , _ = json .Marshal (& rpcError {
110113 Code : - 32600 ,
@@ -119,7 +122,7 @@ func TestSuccesfullDecodeResponseWithErrorCode(t *testing.T) {
119122 res , _ := json .Marshal (expectedResult )
120123
121124 var resp CreateVolumeResponse
122- err := decodeResponse (bytes .NewReader (res ), & resp )
125+ err := decodeResponse (method , bytes .NewReader (res ), & resp )
123126 if err == nil {
124127 t .Log ("No error occurred" )
125128 t .Fail ()
@@ -132,6 +135,8 @@ func TestSuccesfullDecodeResponseWithErrorCode(t *testing.T) {
132135}
133136
134137func TestBadDecodeResponse (t * testing.T ) {
138+ method := "testMethod"
139+ expectedError := fmt .Sprintf (errorMessageFormat , method , emptyResponse )
135140 expectedResult := & response {
136141 ID : "0" ,
137142 Version : "2.0" ,
@@ -140,14 +145,14 @@ func TestBadDecodeResponse(t *testing.T) {
140145 res , _ := json .Marshal (expectedResult )
141146
142147 var resp CreateVolumeResponse
143- err := decodeResponse (bytes .NewReader (res ), & resp )
148+ err := decodeResponse (method , bytes .NewReader (res ), & resp )
144149 if err == nil {
145150 t .Log ("No error occurred" )
146151 t .Fail ()
147152 }
148153
149- if emptyResponse != err .Error () {
150- t .Logf ("Expected: %s got %s\n " , emptyResponse , err .Error ())
154+ if expectedError != err .Error () {
155+ t .Logf ("Expected: %s got %s\n " , expectedError , err .Error ())
151156 t .Fail ()
152157 }
153158}
0 commit comments