第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 aetest.NewContext 代替 endpoints.NewContext

使用 aetest.NewContext 代替 endpoints.NewContext

Go
侃侃爾雅 2021-09-20 14:40:23
我有一個搜索方法:func (sa *SearchApi) Search(c endpoints.Context, r *SearchQuery) (*SearchResults, error) { .. }如您所見,它需要一個 endpoints.Context 例如:ctx := endpoints.NewContext(req1)但是對于aetest,我使用的是不同的上下文:otherCtx, err := aetest.NewContext(&aetest.Options{"", true})特別是這個上下文具有強一致性的額外選項 - 因為我正在設(shè)置數(shù)據(jù)所以我可以測試只讀 api。我無法將 otherCxt 傳遞給我的 Search 方法,因為它不是 endpoints.Context其他Ctx:type Context interface {    appengine.Context    // Login causes the context to act as the given user.    Login(*user.User)    // Logout causes the context to act as a logged-out user.    Logout()    // Close kills the child api_server.py process,    // releasing its resources.    io.Closer}端點.上下文:type Context interface {    appengine.Context    // HTTPRequest returns the request associated with this context.    HTTPRequest() *http.Request    // Namespace returns a replacement context that operates within the given namespace.    Namespace(name string) (Context, error)    // CurrentOAuthClientID returns a clientID associated with the scope.    CurrentOAuthClientID(scope string) (string, error)    // CurrentOAuthUser returns a user of this request for the given scope.    // It caches OAuth info at the first call for future invocations.    //    // Returns an error if data for this scope is not available.    CurrentOAuthUser(scope string) (*user.User, error)}使用aetest測試go-endpoints的推薦方法是什么?是否可以將 aetest 上下文轉(zhuǎn)換為端點上下文?
查看完整描述

2 回答

?
呼如林

TA貢獻1798條經(jīng)驗 獲得超3個贊

根據(jù)亞歷克斯所說,我有以下解決方案:


func TestApi(t *testing.T) {

    inst, _ := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})

    defer inst.Close()

    r, _ := inst.NewRequest("GET", "/", nil)

    c := endpoints.NewContext(r)

    makeCourses(c)

    api := SearchApi{}

    searchQuery := &SearchQuery{"my-search-term", nil}

    searchResults, _ := api.Search(c, searchQuery)

    log.Println("got results %v", searchResults)

}


查看完整回答
反對 回復(fù) 2021-09-20
?
胡說叔叔

TA貢獻1804條經(jīng)驗 獲得超8個贊

這個怎么樣:


inst := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})

r, _ := inst.NewRequest("GET", "/", nil)

c := endpoints.NewContext(r)


sa.Search(c, ...)


查看完整回答
反對 回復(fù) 2021-09-20
  • 2 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號