testutils

package
v0.0.0-...-77aa67c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2013 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTestContext

func CreateTestContext(r *http.Request) appengine.Context

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

func DeleteTestContext(r *http.Request)

DeleteTestContext unregisters a context associated with the request. Subsequent calls to appengine.NewContext(r) will panic.

func NewTestRequest

func NewTestRequest(method, path string, body []byte) (*http.Request, func())

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

type RpcCallOptions struct {
	Timeout time.Duration // if non-zero, overrides RPC default
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL