(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestNewNotFoundError(t *testing.T) { |
| 81 | t.Parallel() |
| 82 | |
| 83 | scenarios := []struct { |
| 84 | message string |
| 85 | data any |
| 86 | expected string |
| 87 | }{ |
| 88 | {"", nil, `{"data":{},"message":"The requested resource wasn't found.","status":404}`}, |
| 89 | {"demo", "rawData_test", `{"data":{},"message":"Demo.","status":404}`}, |
| 90 | {"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"data":{"err1":{"code":"test_code","message":"Test_message."}},"message":"Demo.","status":404}`}, |
| 91 | } |
| 92 | |
| 93 | for i, s := range scenarios { |
| 94 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 95 | e := router.NewNotFoundError(s.message, s.data) |
| 96 | result, _ := json.Marshal(e) |
| 97 | |
| 98 | if str := string(result); str != s.expected { |
| 99 | t.Fatalf("Expected\n%v\ngot\n%v", s.expected, str) |
| 100 | } |
| 101 | }) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func TestNewBadRequestError(t *testing.T) { |
| 106 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…