Closed yumeng110 closed 4 years ago
by default, sql you are expecting in query is translated to regular expression and it is not matching
Hi, I am facing the same problem. My SQL query is simple but still fails. don't know what I missed.
sqlMock := *sqlMock
context, _ := gin.CreateTestContext(httpResponseRecorder)
rows := sqlmock.NewRows([]string{"EMAIL", "PASSWORD"}).
AddRow("testuser@gmail.com", "password").
AddRow("testuser@yahoo.com", "password")
request := request.LoginRequest{
Email: "testuser@yahoo.com",
Password: "password",
}
sqlMock.ExpectQuery(`SELECT EMAIL, PASSWORD from USER_MASTER WHERE EMAIL=:EMAIL`).WithArgs("testuser@yahoo.com").WillReturnRows(rows)
err := sqlMock.ExpectationsWereMet()
Expect(err).NotTo(HaveOccurred())
user, err := authenticationRepository.GetUserByEmailID(context, request)
Expect(err).NotTo(HaveOccurred())
Expect(user).ShouldNot(BeNil())
Expect(user.Email).Should(Equal("testuser@yahoo.com"))
in my case ,i miss Grave (symbol) in my mock sql, solve the problem by change table name from {table_name} to {table_name} with grave symbol in mock sql
hi, i hit a problem:the assert is failed if the sql sentence is related with "ws_hot_status = ?", but pass when "ws_hot_status = 1"
func TestGetFeedidList_ReturnLimitData(t *testing.T) {
}