doujia4619 2015-03-07 03:58 采纳率: 0%
浏览 26
已采纳

使用aetest.NewContext代替endpoints.NewContext来测试具有强一致性的端点

I have a search method:

func (sa *SearchApi) Search(c endpoints.Context, r *SearchQuery) (*SearchResults, error) { .. }

as you can see it takes an endpoints.Context e.g:

ctx := endpoints.NewContext(req1)

however with aetest, i'm using different context:

otherCtx, err := aetest.NewContext(&aetest.Options{"", true})

Particularly this context has extra options for strong consistency - since i'm setting up data so I can test a read only api.

I can't pass the otherCxt through to my Search method because it's not an endpoints.Context

otherCtx:

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
}

endpoints.Context:

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)
}

what's the recommend approach for testing go-endpoints with aetest? Is it possible to just transform the aetest context into the endpoints context?

  • 写回答

2条回答 默认 最新

  • duanqian8867 2015-03-07 12:27
    关注

    How about this:

    inst := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
    r, _ := inst.NewRequest("GET", "/", nil)
    c := endpoints.NewContext(r)
    
    sa.Search(c, ...)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并