我正在嘗試在下面編寫這個(gè)測(cè)試,其他測(cè)試工作正常,但是我在UPDATE查詢時(shí)遇到問(wèn)題func TestDeleteWorkspace(t *testing.T) { conn, mock, repository, err := setup() defer conn.Close() assert.NoError(t, err) uid := uuid.New() // mock.ExpectBegin() mock.ExpectQuery(regexp.QuoteMeta(`UPDATE "workspaces" SET`)).WithArgs(sqlmock.AnyArg(), uid) // mock.ExpectCommit() var e bool e, err = repository.Delete(uid) assert.NoError(t, err) assert.True(t, e) err = mock.ExpectationsWereMet() assert.NoError(t, err)}repository.Delete做這個(gè)查詢func (r *WorkspaceRepository) Delete(id any) (bool, error) { if err := r.db.Delete(&model.Workspace{}, "id = ?", id).Error; err != nil { return false, nil } return true, nil}哪個(gè)運(yùn)行此查詢UPDATE "workspaces" SET "deleted_at"='2022-07-04 09:09:20.778' WHERE id = 'c4610193-b43a-4ed7-9ed6-9d67b3f97502' AND "workspaces"."deleted_at" IS NULL我正在使用Soft-Delete,這就是為什么它是 UPDATE 而不是 DELETE 查詢但是,我收到以下錯(cuò)誤 workspace_test.go:169: Error Trace: workspace_test.go:169 Error: Received unexpected error: there is a remaining expectation which was not matched: ExpectedQuery => expecting Query, QueryContext or QueryRow which: - matches sql: 'UPDATE "workspaces" SET' - is with arguments: 0 - 28e7aa46-7a22-4dc7-b3ce-6cf02af525ca 1 - {}我做錯(cuò)了什么?
調(diào)用回滾事務(wù),不是預(yù)期的,下一個(gè)預(yù)期是:ExpectedQuery
慕尼黑5688855
2023-01-03 09:46:43