Here is my test:
func TestCashDepositAPI(t *testing.T) {
....
testCases := []struct {
name string // name of the test scenario - ok, notfound etc
reqBody gin.H
setupAuth func(t *testing.T, request *http.Request, tokenMaker token.Maker)
buildStubs func(store *mockdb.MockStore)
checkResponse func(t *testing.T, recoder *httptest.ResponseRecorder)
}{
{
name: "OK",
reqBody: gin.H{
"AccountNo": account.Accountno,
"Amount": amount,
},
setupAuth: func(t *testing.T, request *http.Request, tokenMaker token.Maker) {
.... code omitted ... though this part working
},
buildStubs: func(store *mockdb.MockStore) {
store.EXPECT().GetAccountForUpdate(gomock.Any(), gomock.Eq(account.Accountno)).Times(1).Return(account, nil)
arg := db.DepositTxParams{
.... code omitted ... though this part working
}
store.EXPECT().DepositTx(gomock.Any(), gomock.Eq(arg)).Times(1)
},
checkResponse: func(t *testing.T, recorder *httptest.ResponseRecorder) {
require.Equal(t, http.StatusOK, recorder.Code)
},
},
}
for i := range testCases {
tc := testCases[i]
t.Run(tc.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
store := mockdb.NewMockStore(ctrl)
tc.buildStubs(store)
server := newTestServer(t, limiter, store, envConfig)
recorder := httptest.NewRecorder()
// Marshal reqBody data to JSON
data, err := json.Marshal(tc.reqBody)
require.NoError(t, err)
url := "/sendCashWithdrawal"
request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(data))
require.NoError(t, err)
tc.setupAuth(t, request, server.tokenMaker)
server.router.ServeHTTP(recorder, request)
tc.checkResponse(t, recorder)
})
}
}
Kindly assist. Been stuck for days. Here is the error in details:
"missing call(s) to *mockdb.MockStore.GetAccountForUpdate()"
"missing call(s) to *mockdb.MockStore.DepositTx()"
Tried everything I know. I see my code is okay but I still get the error.