blob: f580467fe1cb8249f89c05faa5abce2ab4c44f93 [file] [log] [blame]
package aetest
import (
// Instance represents a running instance of the development API Server.
type Instance interface {
// Close kills the child process, releasing its resources.
// NewRequest returns an *http.Request associated with this instance.
NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)
// Options is used to specify options when creating an Instance.
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
// SupportDatastoreEmulator is whether use Cloud Datastore Emulator or
// use old SQLite based Datastore backend or use default settings.
SupportDatastoreEmulator *bool
// SuppressDevAppServerLog is whether the dev_appserver running in tests
// should output logs.
SuppressDevAppServerLog bool
// StartupTimeout is a duration to wait for instance startup.
// By default, 15 seconds.
StartupTimeout time.Duration
// NewContext starts an instance of the development API server, and returns
// a context that will route all API calls to that server, as well as a
// closure that must be called when the Context is no longer required.
func NewContext() (context.Context, func(), error) {
inst, err := NewInstance(nil)
if err != nil {
return nil, nil, err
req, err := inst.NewRequest("GET", "/", nil)
if err != nil {
return nil, nil, err
ctx := appengine.NewContext(req)
return ctx, func() {
}, nil
// PrepareDevAppserver is a hook which, if set, will be called before the
// is started, each time it is started. If aetest.NewContext
// is invoked from the goapp test tool, this hook is unnecessary.
var PrepareDevAppserver func() error