(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func TestNewForbiddenError(t *testing.T) { |
| 131 | t.Parallel() |
| 132 | |
| 133 | scenarios := []struct { |
| 134 | message string |
| 135 | data any |
| 136 | expected string |
| 137 | }{ |
| 138 | {"", nil, `{"data":{},"message":"You are not allowed to perform this request.","status":403}`}, |
| 139 | {"demo", "rawData_test", `{"data":{},"message":"Demo.","status":403}`}, |
| 140 | {"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"data":{"err1":{"code":"test_code","message":"Test_message."}},"message":"Demo.","status":403}`}, |
| 141 | } |
| 142 | |
| 143 | for i, s := range scenarios { |
| 144 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 145 | e := router.NewForbiddenError(s.message, s.data) |
| 146 | result, _ := json.Marshal(e) |
| 147 | |
| 148 | if str := string(result); str != s.expected { |
| 149 | t.Fatalf("Expected\n%v\ngot\n%v", s.expected, str) |
| 150 | } |
| 151 | }) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func TestNewUnauthorizedError(t *testing.T) { |
| 156 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…