I am trying to test my handler layer by mocking the service layer using go/mock.
When running the test get these errors
Here is how I do the mocking:
mockBehavior: func(s *mock_service.MockUploader, ctx context.Context, data model.Data) {
s.EXPECT().XMLFinesService(ctx, data)
}
And the Run function:
for _, testCase := range testTable {
t.Run(testCase.name, func(t *testing.T) {
// Init
ctrl := gomock.NewController(t)
cfg := &config.Config{}
upload := mock_service.NewMockUploader(ctrl)
testCase.mockBehavior(upload, testCase.inputContext, testCase.inputData)
services := &service.Services{Uploader: upload}
handler := NewHandlers(services, cfg)
// Test server
e := echo.New()
e.POST("/uploadXML", handler.Upload.UploadXMLFines())
// Test request
w := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/uploadXML", bytes.NewBufferString(testCase.inputBody))
// Perform request
e.ServeHTTP(w, req)
// Assert
assert.Equal(t, testCase.expectedStatusCode, w.Code)
assert.Equal(t, testCase.expectedRequestBody, w.Body.String())
})
}