到这里。试图弄清楚如何使用SQL mock v2。这是我的界面:type OrderPersister interface { FetchOrderById(string) (*Order, error)}我对该接口的实现:type DbPersister struct { Config config.DbConfig GormDB *gorm.DB}func (op DbPersister) FetchOrderById(orderId string) (*Order, error) { Order := &Order{} orderUuid, err := uuid.Parse(orderId) if err != nil { return nil, err } if err := op.GormDB.Table("orders"). Select(`orders.order_id, orders.user_id, orders.quantity, orders.status addresses.line_1, users.email`). Joins("join addresses on addresses.address_id = orders.address_id"). Joins("join users on users.user_id = orders.user_id"). Where("orders.order_id = ?", orderUuid). First(Order).Error; err != nil { return nil, err } return Order, nil}当它运行时,测试失败,原因如下:--- FAIL: TestInit (0.00s) --- FAIL: TestInit/TestFetchOrderById (0.00s) db_test.go:67: Error Trace: db_test.go:67 suite.go:137 panic.go:969 rows.go:134 db_test.go:99 Error: Received unexpected error: there is a remaining expectation which was not matched: ExpectedQuery => expecting Query, QueryContext or QueryRow which: - matches sql: 'SELECT' - is without arguments Test: TestInit/TestFetchOrderById我要做的就是确认使用函数GormDB中指定的 SELECT 语句查询了该实例FetchOrderById。有人知道我需要做什么才能实现这一目标并通过测试吗?
- 1 回答
- 0 关注
- 498 浏览
添加回答
举报
0/150
提交
取消
