Untitled
unknown
plain_text
a year ago
887 B
4
Indexable
t.Run("Case read 05 -> find_all: Should return error message (internal Error)", func(t *testing.T) { // ARRANGE // -service sv := service.NewEmployeeDefaultMock() // -handler hd := handler.NewEmployeeDefault(sv) handlerFunc := hd.GetAll() // set the find all mock sv.On("FindAll").Return([]internal.Employee{}, internal.ErrInternalServerError) // request // use of http.NewRequest to create a new request for testing req := httptest.NewRequest(http.MethodGet, "/api/v1/employees", nil) //response res := httptest.NewRecorder() //ACT handlerFunc(res, req) // ASSERT // set the expected body expectedBody := ` {"message":"Internal server error", "status":"Internal Server Error"}` // compare status code require.Equal(t, http.StatusInternalServerError, res.Code) // compare body require.JSONEq(t, expectedBody, res.Body.String()) }) }
Editor is loading...
Leave a Comment