Documentation ¶
Overview ¶
Package aetest provides an appengine.Context for use in tests.
An example test file:
package foo_test import ( "testing" "appengine/memcache" "appengine/aetest" ) func TestFoo(t *testing.T) { c, err := aetest.NewContext(nil) if err != nil { t.Fatal(err) } defer c.Close() it := &memcache.Item{ Key: "some-key", Value: []byte("some-value"), } err = memcache.Set(c, it) if err != nil { t.Fatalf("Set err: %v", err) } it, err = memcache.Get(c, "some-key") if err != nil { t.Fatalf("Get err: %v; want no error", err) } if g, w := string(it.Value), "some-value" ; g != w { t.Errorf("retrieved Item.Value = %q, want %q", g, w) } }
The environment variable APPENGINE_DEV_APPSERVER specifies the location of the dev_appserver.py executable to use. If unset, the system PATH is consulted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var PrepareDevAppserver func() error
PrepareDevAppserver is a hook which, if set, will be called before the dev_appserver.py is started, each time it is started. If aetest.NewContext is invoked from the goapp test tool, this hook is unnecessary.
Functions ¶
Types ¶
type Context ¶
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 }
Context is an appengine.Context that sends all App Engine API calls to an instance of the API server.
func NewContext ¶
NewContext launches an instance of api_server.py and returns a Context that delegates all App Engine API calls to that instance. If opts is nil the default values are used.
type Instance ¶
type Instance interface { // Close kills the child api_server.py process, releasing its resources. io.Closer // NewRequest returns an *http.Request associated with this instance. NewRequest(method, urlStr string, body io.Reader) (*http.Request, error) // contains filtered or unexported methods }
Instance represents a running instance of the development API Server.
func NewInstance ¶
NewInstance launches a running instance of api_server.py which can be used for multiple test Contexts that delegate all App Engine API calls to that instance. If opts is nil the default values are used.
type Options ¶
type Options struct { // AppID specifies the App ID to use during tests. // By default, "testapp". AppID string // StronglyConsistentDatastore is whether the local datastore should be // strongly consistent. This will diverge from production behaviour. StronglyConsistentDatastore bool }
Options is used to specify options when creating an Instance.