-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from alex-semenyuk/increase_coverage_error_map…
…ping Increase code coverage
- Loading branch information
Showing
2 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package tezos | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMapError(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
methodType tezosRPCMethodCategory | ||
err error | ||
errorReason ffcapi.ErrorReason | ||
}{ | ||
{ | ||
name: "BlockRPCMethods with 404 Status error", | ||
methodType: blockRPCMethods, | ||
err: errors.New("status 404"), | ||
errorReason: ffcapi.ErrorReasonNotFound, | ||
}, | ||
{ | ||
name: "SendRPCMethods with counter_in_the_past error", | ||
methodType: sendRPCMethods, | ||
err: errors.New("counter_in_the_past"), | ||
errorReason: ffcapi.ErrorReasonNonceTooLow, | ||
}, | ||
{ | ||
name: "BlockRPCMethods with some non 404 Status error", | ||
methodType: blockRPCMethods, | ||
err: errors.New("error"), | ||
errorReason: ffcapi.ErrorReason(""), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
res := mapError(tc.methodType, tc.err) | ||
|
||
assert.Equal(t, tc.errorReason, res) | ||
}) | ||
} | ||
} | ||
|
||
func TestErrorStatusNonHttpError(t *testing.T) { | ||
errorStatus := ErrorStatus(errors.New("error")) | ||
|
||
assert.Equal(t, errorStatus, 0) | ||
} | ||
|
||
func TestErrorStatusHttpError(t *testing.T) { | ||
err := httpError{ | ||
request: "request", | ||
status: "status", | ||
statusCode: 400, | ||
body: []byte("body"), | ||
} | ||
|
||
errorStatus := ErrorStatus(&err) | ||
|
||
assert.Equal(t, errorStatus, err.StatusCode()) | ||
assert.Equal(t, err.Status(), "status") | ||
assert.Equal(t, err.StatusCode(), 400) | ||
assert.Equal(t, err.Request(), "request") | ||
assert.Equal(t, err.Body(), []byte("body")) | ||
assert.Equal(t, err.Error(), "rpc: request status 400 (body)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters