mirror of
https://gitlab.durp.info/durfy/modules/durpify.git
synced 2026-05-07 16:10:28 -05:00
formating
This commit is contained in:
parent
b4562a1da4
commit
3573b46fd9
3 changed files with 63 additions and 15 deletions
|
|
@ -52,8 +52,13 @@ func (message *StandardError) SendReponse(w http.ResponseWriter) {
|
|||
}
|
||||
}
|
||||
|
||||
// NewFailureResponse returns a new instance of StandardError with the given message, status code and description.
|
||||
func NewFailureResponse(message string, status int, description []string) StandardError {
|
||||
// NewFailureResponse returns a new instance of StandardError with the given
|
||||
// message, status code and description.
|
||||
func NewFailureResponse(
|
||||
message string,
|
||||
status int,
|
||||
description []string,
|
||||
) StandardError {
|
||||
return StandardError{
|
||||
Message: message,
|
||||
Status: status,
|
||||
|
|
@ -61,7 +66,8 @@ func NewFailureResponse(message string, status int, description []string) Standa
|
|||
}
|
||||
}
|
||||
|
||||
// NewMessageResponse returns a new instance of StandardMessage with the given message and status code.
|
||||
// NewMessageResponse returns a new instance of StandardMessage with the given
|
||||
// message and status code.
|
||||
func NewMessageResponse(message interface{}, status int) *StandardMessage {
|
||||
return &StandardMessage{
|
||||
Message: message,
|
||||
|
|
@ -69,7 +75,8 @@ func NewMessageResponse(message interface{}, status int) *StandardMessage {
|
|||
}
|
||||
}
|
||||
|
||||
// NewBasicResponse returns a new basic instance of StandardMessage with the message of OK and Status OK.
|
||||
// NewBasicResponse returns a new basic instance of StandardMessage with the
|
||||
// message of OK and Status OK.
|
||||
func NewBasicResponse() *StandardMessage {
|
||||
return &StandardMessage{
|
||||
Message: BasicMessage{
|
||||
|
|
@ -85,7 +92,10 @@ func setHeader(w *http.ResponseWriter, statusCode int) {
|
|||
(*w).Header().Set("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
type APIFunc func(w http.ResponseWriter, r *http.Request) (*StandardMessage, error)
|
||||
type APIFunc func(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) (*StandardMessage, error)
|
||||
|
||||
func Make(handler APIFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ func TestSendResponseStandardMessage(t *testing.T) {
|
|||
// Check that the content type header is set to "application/json"
|
||||
contentType := w.Header().Get("Content-Type")
|
||||
if contentType != "application/json" {
|
||||
t.Errorf("Expected content type to be 'application/json', but got %s", contentType)
|
||||
t.Errorf(
|
||||
"Expected content type to be 'application/json', but got %s",
|
||||
contentType,
|
||||
)
|
||||
}
|
||||
|
||||
// Check that the message is written to the response body correctly
|
||||
|
|
@ -59,7 +62,11 @@ func TestSendResponseStandardError(t *testing.T) {
|
|||
// Check that the content type header is set to "application/json"
|
||||
contentType := w.Header().Get("Content-Type")
|
||||
if contentType != "application/json" {
|
||||
t.Errorf("Expected content type to be 'application/json', but got %s", contentType)
|
||||
t.Errorf(
|
||||
"Expected content type to be 'application/json',"+
|
||||
" but got %s",
|
||||
contentType,
|
||||
)
|
||||
}
|
||||
|
||||
// Check that the message is written to the response body correctly
|
||||
|
|
@ -70,7 +77,11 @@ func TestSendResponseStandardError(t *testing.T) {
|
|||
}
|
||||
|
||||
if response.Message != resp.Message {
|
||||
t.Errorf("Expected Message of %s but got %s", resp.Message, response.Message)
|
||||
t.Errorf(
|
||||
"Expected Message of %s but got %s",
|
||||
resp.Message,
|
||||
response.Message,
|
||||
)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(resp, response) {
|
||||
|
|
@ -78,7 +89,8 @@ func TestSendResponseStandardError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// NewFailureResponse returns a new instance of StandardError with the given message, status code and description.
|
||||
// NewFailureResponse returns a new instance of StandardError with the given
|
||||
// message, status code and description.
|
||||
func TestNewFailureResponse(t *testing.T) {
|
||||
message := "An error has occured"
|
||||
status := http.StatusInternalServerError
|
||||
|
|
@ -86,13 +98,25 @@ func TestNewFailureResponse(t *testing.T) {
|
|||
resp := NewFailureResponse(message, status, description)
|
||||
|
||||
if resp.Status != status {
|
||||
t.Errorf("Expected Status to be %d but got %d", status, resp.Status)
|
||||
t.Errorf(
|
||||
"Expected Status to be %d but got %d",
|
||||
status,
|
||||
resp.Status,
|
||||
)
|
||||
}
|
||||
if resp.Message != message {
|
||||
t.Errorf("Expected Status to be %s but got %s", message, resp.Message)
|
||||
t.Errorf(
|
||||
"Expected Status to be %s but got %s",
|
||||
message,
|
||||
resp.Message,
|
||||
)
|
||||
}
|
||||
if !reflect.DeepEqual(description, resp.Description) {
|
||||
t.Errorf("Expected Status to be %v but got %v", description, resp.Description)
|
||||
t.Errorf(
|
||||
"Expected Status to be %v but got %v",
|
||||
description,
|
||||
resp.Description,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,9 +129,17 @@ func TestNewMessageResponse(t *testing.T) {
|
|||
resp := NewMessageResponse(message, http.StatusOK)
|
||||
|
||||
if resp.Status != http.StatusOK {
|
||||
t.Errorf("Expected Status to be %d but got %d", http.StatusOK, resp.Status)
|
||||
t.Errorf(
|
||||
"Expected Status to be %d but got %d",
|
||||
http.StatusOK,
|
||||
resp.Status,
|
||||
)
|
||||
}
|
||||
if !reflect.DeepEqual(message, resp.Message) {
|
||||
t.Errorf("Expected Message to be %s but got %s", message, resp.Message)
|
||||
t.Errorf(
|
||||
"Expected Message to be %s but got %s",
|
||||
message,
|
||||
resp.Message,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue