diff --git a/internal/noderpc/rpc.go b/internal/noderpc/rpc.go index 9150b3716..2283c4667 100644 --- a/internal/noderpc/rpc.go +++ b/internal/noderpc/rpc.go @@ -99,9 +99,7 @@ func (rpc *NodeRPC) checkStatusCode(r io.Reader, statusCode int, checkStatusCode return err } invalidResponseErr.Raw = data - if err := json.Unmarshal(data, &invalidResponseErr.Errors); err != nil { - return errors.Wrap(invalidResponseErr, err.Error()) - } + _ = json.Unmarshal(data, &invalidResponseErr.Errors) return invalidResponseErr default: return nil diff --git a/internal/noderpc/rpc_test.go b/internal/noderpc/rpc_test.go new file mode 100644 index 000000000..f8898f3b0 --- /dev/null +++ b/internal/noderpc/rpc_test.go @@ -0,0 +1,66 @@ +package noderpc + +import ( + "io" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNodeRPC_checkStatusCode(t *testing.T) { + tests := []struct { + name string + r io.Reader + statusCode int + checkStatusCode bool + wantErr bool + errString string + }{ + { + name: "404 error", + r: strings.NewReader("404 page not found"), + statusCode: 400, + checkStatusCode: true, + wantErr: true, + errString: "404 page not found", + }, { + name: "200", + r: strings.NewReader(""), + statusCode: 200, + checkStatusCode: true, + wantErr: false, + }, { + name: "501", + r: strings.NewReader("node unavailiable"), + statusCode: 501, + checkStatusCode: true, + wantErr: true, + errString: "is unavailiable: 501", + }, { + name: "no checking", + r: strings.NewReader("node unavailiable"), + statusCode: 400, + checkStatusCode: false, + wantErr: false, + errString: "", + }, { + name: "501 with no checking", + r: strings.NewReader("node unavailiable"), + statusCode: 501, + checkStatusCode: false, + wantErr: true, + errString: "is unavailiable: 501", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rpc := new(NodeRPC) + err := rpc.checkStatusCode(tt.r, tt.statusCode, tt.checkStatusCode) + require.Equal(t, tt.wantErr, err != nil) + if err != nil { + require.ErrorContains(t, err, tt.errString) + } + }) + } +}