Documentation ¶
Overview ¶
Although most of the methods here are proxies to appengine_internal methods, it is better to use these instead of invoking appengine_internal directly.
App Engine internals might change over time (even frequently) so if your tests use methods from this package you'll never have to change them.
Index ¶
- func CreateTestContext(r *http.Request) appengine.Context
- func DeleteTestContext(r *http.Request)
- func NewTestRequest(method, path string, body []byte) (*http.Request, func())
- func RegisterAPIOverride(service, method string, f RpcStubFunc) func()
- func SetDevAppServer(dev bool)
- func UnregisterAPIOverride(service, method string)
- type RpcCallOptions
- type RpcStubFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTestContext ¶
CreateTestContext creates and registers a new appengine.Context associated with the request so that subsequent calls to appentine.NewContext(r) anywhere in the code will successfully return the context.
The caller is responsible to invoke DeleteTestContext(ctx) at the end of a test.
func DeleteTestContext ¶
DeleteTestContext unregisters a context associated with the request. Subsequent calls to appengine.NewContext(r) will panic.
func NewTestRequest ¶
NewTestRequest creates http.Request and appengine.Context associated with the request. It panics if the request cannot be created.
Returns the newly created request and a function that removes associated context. The caller is responsible to invoke this function at the end of a test.
func RegisterAPIOverride ¶
func RegisterAPIOverride(service, method string, f RpcStubFunc) func()
RegisterAPIOverride replaces (stubs out) the implementation of an API RPC call. The caller is responsible to unregister the override at the end of a test.
Returns a function that can unregister the stub. Here's an example:
func TestSomething(t *testing.T) { rpcStub = func(in, out proto.Message, *RpcCallOptions) error { req := in.(pb.SomeProtoRequest) resp := out.(pb.SomeProtoResponse) // do something with req / resp or return an error } unregister = RegisterAPIOverride("user", "SomeRpcMethod", rpcStub) defer unregister() // test code that (probably indirectly) calls "user.SomeRpcMethod" }
func SetDevAppServer ¶
func SetDevAppServer(dev bool)
SetDevAppServer can make an app think it's running on production servers.
func UnregisterAPIOverride ¶
func UnregisterAPIOverride(service, method string)
UnregisterAPIOverride removes stubbed API RPC implementation from registered overrides.
Types ¶
type RpcCallOptions ¶
RpcCallOptions is the equivalent of appengine_internal.CallOptions.
type RpcStubFunc ¶
type RpcStubFunc func(in, out proto.Message, opts *RpcCallOptions) error
RpcStubFunc is a function type that replaces an API RPC implementation.