-
Notifications
You must be signed in to change notification settings - Fork 25
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 #10 from Xaxxis/main
v1.3.0 Comply midtrans error with Golang error interface
- Loading branch information
Showing
7 changed files
with
98 additions
and
16 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
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
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
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,41 @@ | ||
package midtrans | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
assert "github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestErrorStruct(t *testing.T) { | ||
err := &Error{ | ||
Message: "Error Test Message", | ||
StatusCode: 200, | ||
RawError: errors.New("TEST FROM GO ERROR"), | ||
RawApiResponse: nil, | ||
} | ||
var midError *Error | ||
assert.Error(t, err) | ||
assert.True(t, true, errors.Is(err, err)) | ||
assert.True(t, true, errors.As(err, &midError)) | ||
assert.Equal(t, `Error Test Message`, err.GetMessage()) | ||
assert.Equal(t, 200, err.GetStatusCode()) | ||
assert.Equal(t, "Error Test Message: TEST FROM GO ERROR", err.Error()) | ||
} | ||
|
||
func TestErrorResponse(t *testing.T) { | ||
serverKey := "dummy" | ||
c := GetHttpClient(Environment) | ||
jsonReq, _ := json.Marshal("{\"transaction_details\": {\"order_id\": \"TEST-1648108994111\", \"gross_amount\": 10000}}") | ||
err := c.Call(http.MethodPost, "https://app.midtrans.com/snap/v1/transactions", &serverKey, nil, bytes.NewBuffer(jsonReq), nil) | ||
|
||
var midError *Error | ||
assert.True(t, true, errors.Is(err, err)) | ||
assert.True(t, true, errors.As(err, &midError)) | ||
assert.Error(t, err) | ||
assert.Equal(t, 401, err.StatusCode) | ||
assert.Equal(t, "app.midtrans.com", err.RawApiResponse.Request.Host) | ||
} |
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
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
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