-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: on malformed error response, ensure more context
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package routingv8_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.einride.tech/here/routingv8" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestRouteError(t *testing.T) { | ||
for _, tt := range []*struct { | ||
name string | ||
expectedErrorString string | ||
responseError routingv8.ResponseError | ||
}{ | ||
{ | ||
name: "normally serialized", | ||
responseError: routingv8.ResponseError{ | ||
Response: &routingv8.HereErrorResponse{ | ||
Title: "Unknown", | ||
Status: 500, | ||
Code: "ErrorCode", | ||
Cause: "Random Cause", | ||
Action: "Do it right", | ||
}, | ||
}, | ||
expectedErrorString: "Title: Unknown, Status: 500, Code: ErrorCode, Cause: Random Cause, Action: Do it right", | ||
}, | ||
{ | ||
name: "response not present", | ||
responseError: routingv8.ResponseError{ | ||
HTTPBody: "{}", | ||
}, | ||
expectedErrorString: "Response: {} StatusCode: 0", | ||
}, | ||
{ | ||
name: "response malformed", | ||
responseError: routingv8.ResponseError{ | ||
Response: &routingv8.HereErrorResponse{}, | ||
HTTPBody: "{}", | ||
}, | ||
expectedErrorString: "Response: {} StatusCode: 0", | ||
}, | ||
{ | ||
name: "response with 0 status code", | ||
responseError: routingv8.ResponseError{ | ||
Response: &routingv8.HereErrorResponse{ | ||
Status: 0, | ||
}, | ||
HTTPBody: "{}", | ||
}, | ||
expectedErrorString: "Response: {} StatusCode: 0", | ||
}, | ||
} { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.responseError.Error(), tt.expectedErrorString) | ||
}) | ||
} | ||
} |