We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write some tests to check if the endpoints do what they have to do
e.g.
package main_test import ( "net/http" "net/http/httptest" "testing" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "yourpackage/dataservice" "yourpackage/restapi" "yourpackage/restapi/mocks" ) func TestGetUser(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() // Mock-Implementierung der Datenzugriffsschicht mockDataService := mocks.NewMockDataService(ctrl) mockDataService.EXPECT().GetUser(1).Return(&dataservice.User{ID: 1, Name: "John"}, nil) // REST-API-Handler initialisieren und den DataService setzen apiHandler := restapi.NewAPIHandler() apiHandler.SetDataService(mockDataService) // HTTP-Request und -Response simulieren req, _ := http.NewRequest("GET", "/users/1", nil) rec := httptest.NewRecorder() // Handler aufrufen apiHandler.ServeHTTP(rec, req) // Überprüfen der HTTP-Response assert.Equal(t, http.StatusOK, rec.Code) assert.Equal(t, `{"id":1,"name":"John"}`, rec.Body.String()) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Write some tests to check if the endpoints do what they have to do
e.g.
The text was updated successfully, but these errors were encountered: