@@ -38,43 +38,23 @@ func TestResponder_getStatusCode(t *testing.T) {
38
38
data interface {}
39
39
err error
40
40
statusCode int
41
+ errObj interface {}
41
42
}{
42
- {"success case" , http .MethodGet , "success response" , nil , http .StatusOK },
43
- {"post with response body" , http .MethodPost , "entity created" , nil , http .StatusCreated },
44
- {"post with nil response" , http .MethodPost , nil , nil , http .StatusAccepted },
45
- {"success delete" , http .MethodDelete , nil , nil , http .StatusNoContent },
46
- {"invalid route error" , http .MethodGet , nil , ErrorInvalidRoute {}, http .StatusNotFound },
47
- {"internal server error" , http .MethodGet , nil , http .ErrHandlerTimeout , http .StatusInternalServerError },
43
+ {"success case" , http .MethodGet , "success response" , nil , http .StatusOK , nil },
44
+ {"post with response body" , http .MethodPost , "entity created" , nil , http .StatusCreated , nil },
45
+ {"post with nil response" , http .MethodPost , nil , nil , http .StatusAccepted , nil },
46
+ {"success delete" , http .MethodDelete , nil , nil , http .StatusNoContent , nil },
47
+ {"invalid route error" , http .MethodGet , nil , ErrorInvalidRoute {}, http .StatusNotFound ,
48
+ map [string ]interface {}{"message" : ErrorInvalidRoute {}.Error ()}},
49
+ {"internal server error" , http .MethodGet , nil , http .ErrHandlerTimeout , http .StatusInternalServerError ,
50
+ map [string ]interface {}{"message" : http .ErrHandlerTimeout .Error ()}},
48
51
}
49
52
50
53
for i , tc := range tests {
51
- statusCode := getStatusCode (tc .method , tc .data , tc .err )
54
+ statusCode , errObj := getStatusCode (tc .method , tc .data , tc .err )
52
55
53
56
assert .Equal (t , tc .statusCode , statusCode , "TEST[%d], Failed.\n %s" , i , tc .desc )
54
- }
55
- }
56
-
57
- func TestResponder_getErrResponse (t * testing.T ) {
58
- tests := []struct {
59
- desc string
60
- err error
61
- reason []string
62
- details interface {}
63
- }{
64
- {"success case" , nil , nil , nil },
65
- {"invalid param error" , ErrorInvalidParam {}, []string {ErrorInvalidParam {}.Error ()}, nil },
66
- {"multiple errors" , MultipleErrors {Errors : []error {ErrorMissingParam {}, CustomError {Reason : ErrorEntityAlreadyExist {}.Error ()}}},
67
- []string {ErrorMissingParam {}.Error (), CustomError {Reason : alreadyExistsMessage }.Error ()}, nil },
68
- {"custom error" , CustomError {Reason : ErrorEntityNotFound {}.Error ()}, []string {ErrorEntityNotFound {}.Error ()}, nil },
69
- }
70
-
71
- for i , tc := range tests {
72
- errObj := getErrResponse (tc .err )
73
-
74
- for j , err := range errObj {
75
- assert .Equal (t , tc .reason [j ], err .Reason , "TEST[%d], Failed.\n %s" , i , tc .desc )
76
57
77
- assert .Equal (t , tc .details , err .Details , "TEST[%d], Failed.\n %s" , i , tc .desc )
78
- }
58
+ assert .Equal (t , tc .errObj , errObj , "TEST[%d], Failed.\n %s" , i , tc .desc )
79
59
}
80
60
}
0 commit comments