Documentation
¶
Overview ¶
Package appenginetesting provides an appengine.Context for testing.
Index ¶
- Constants
- Variables
- type Context
- func (c *Context) AppID() string
- func (c *Context) Call(service, method string, in, out appengine_internal.ProtoMessage, ...) error
- func (c *Context) Close()
- func (c *Context) Criticalf(format string, args ...interface{})
- func (c *Context) Debugf(format string, args ...interface{})
- func (c *Context) Errorf(format string, args ...interface{})
- func (c *Context) FullyQualifiedAppID() string
- func (c *Context) Infof(format string, args ...interface{})
- func (c *Context) Login(email string, admin bool)
- func (c *Context) Logout()
- func (c *Context) Request() interface{}
- func (c *Context) Warningf(format string, args ...interface{})
- type ContextRecorder
- type Options
Examples ¶
Constants ¶
View Source
const DefaultAPIVersion = "go1"
Default API Version
Variables ¶
View Source
var APIVersion = DefaultAPIVersion
API version of golang. It is used for app.yaml of dev_server setting.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context implements appengine.Context by running a dev_appserver.py process as a child and proxying all Context calls to the child. Use NewContext to create one.
func NewContext ¶
NewContext returns a new AppEngine context with an empty datastore, etc. A nil Options is valid and means to use the default values.
Example (Datastore) ¶
// Create mocked context.
c, err := NewContext(nil)
if err != nil {
fmt.Println("initilizing context:", err)
return
}
// Close the context when we are done.
defer c.Close()
// Get an element from the datastore.
k := datastore.NewKey(c, "Entity", "stringID", 0, nil)
e := ""
if err := datastore.Get(c, k, &e); err != nil {
fmt.Println("datastore get:", err)
return
}
// Put an element in the datastore.
if _, err := datastore.Put(c, k, &e); err != nil {
fmt.Println("datastore put:", err)
return
}
Example (User) ¶
// Create mocked context.
c, err := NewContext(nil)
if err != nil {
fmt.Println("initilizing context:", err)
return
}
// Close the context when we are done.
defer c.Close()
// Log a user in.
c.Login("test@example.com", true)
// Get the user.
u := user.Current(c)
if u == nil {
fmt.Println("we didn't get a user!")
return
}
fmt.Println("Email:", u.Email)
fmt.Println("Admin:", u.Admin)
Output: Email: test@example.com Admin: true
func (*Context) Call ¶
func (c *Context) Call(service, method string, in, out appengine_internal.ProtoMessage, opts *appengine_internal.CallOptions) error
func (*Context) Close ¶
func (c *Context) Close()
Close kills the child dev_appserver.py process, releasing its resources.
Close is not part of the appengine.Context interface.
func (*Context) FullyQualifiedAppID ¶
type ContextRecorder ¶
type ContextRecorder struct {
// contains filtered or unexported fields
}
func NewContextRecorder ¶
func NewContextRecorder(opts *Options) *ContextRecorder
func (*ContextRecorder) Context ¶
func (r *ContextRecorder) Context() *Context
Click to show internal directories.
Click to hide internal directories.