1 回答

TA貢獻1794條經(jīng)驗 獲得超8個贊
一些東西:
創(chuàng)建一個將由
datastore.Storage
您的模擬商店實現(xiàn)的接口。使用上述接口作為參數(shù)類型 in
EventHandler
(not a pointer to the interface)。將指針傳遞給您的
MockStore
toEventHandler
,因為該Get
方法是為指向結構的指針定義的。
您更新后的代碼應如下所示:
type Store interface {
Get() (interface{}, bool) // change as needed
Set(interface{}) bool
}
type MockStore struct {
mock.Mock
}
func (s *MockStore) Get() ...
func EventHandler(w http.ResponseWriter, r *http.Request,bucket datastore.Storage){
//Does HTTP stuff and stores things in a data store
// Need to mock out the data store get/sets
}
// Later in my Tests
ms := &MockStore{}
EventHandler(w,r,ms)
- 1 回答
- 0 關注
- 193 瀏覽
添加回答
舉報