(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestNewBadRequestError(t *testing.T) { |
| 106 | t.Parallel() |
| 107 | |
| 108 | scenarios := []struct { |
| 109 | message string |
| 110 | data any |
| 111 | expected string |
| 112 | }{ |
| 113 | {"", nil, `{"data":{},"message":"Something went wrong while processing your request.","status":400}`}, |
| 114 | {"demo", "rawData_test", `{"data":{},"message":"Demo.","status":400}`}, |
| 115 | {"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"data":{"err1":{"code":"test_code","message":"Test_message."}},"message":"Demo.","status":400}`}, |
| 116 | } |
| 117 | |
| 118 | for i, s := range scenarios { |
| 119 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 120 | e := router.NewBadRequestError(s.message, s.data) |
| 121 | result, _ := json.Marshal(e) |
| 122 | |
| 123 | if str := string(result); str != s.expected { |
| 124 | t.Fatalf("Expected\n%v\ngot\n%v", s.expected, str) |
| 125 | } |
| 126 | }) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | func TestNewForbiddenError(t *testing.T) { |
| 131 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…