vendredi 6 mars 2015

use aetest.NewContext in place of endpoints.NewContext for testing go-endpoints with strong consistency

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?


Aucun commentaire:

Enregistrer un commentaire