-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocks_common.go
More file actions
36 lines (30 loc) · 1.04 KB
/
mocks_common.go
File metadata and controls
36 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package awsmocker
import "net/http"
// Returns an error response for a given service/action call
func Mock_Failure(service, action string) *MockedEndpoint {
return Mock_Failure_WithCode(0, service, action, "AccessDenied", "This mock was requested to fail")
}
// Mocks a specific Service:Action call to return an error
func Mock_Failure_WithCode(statusCode int, service, action, errorCode, errorMessage string) *MockedEndpoint {
return &MockedEndpoint{
Request: &MockedRequest{
Service: service,
Action: action,
},
Response: MockResponse_Error(statusCode, errorCode, errorMessage),
}
}
// Returns an error response with a custom code and message
func MockResponse_Error(statusCode int, errorCode, errorMessage string) *MockedResponse {
if statusCode == 0 {
statusCode = 400
}
errObj := generateErrorStruct(statusCode, errorCode, errorMessage)
return &MockedResponse{
Handler: func(rr *ReceivedRequest) *http.Response {
resp := errObj.getResponse(rr).toHttpResponse(rr.HttpRequest)
resp.StatusCode = statusCode
return resp
},
}
}