appenginetesting

package module
v0.0.0-...-13bf82b Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2013 License: Apache-2.0 Imports: 18 Imported by: 0

README

appenginetesting

Fork of gae-go-testing with a few minor changes:

  • renamed for nicer import syntax (that IDEA's Go Plugin won't highlight as an error)
  • added +build tags so that it compiles
  • simplified install instructions.

As of GAE 1.7.5, we now keep tags of the repository that are known to be compatible with each GAE release. If you are not using the latest GAE release, please use the associated tag.

Installation

Set environment variables :

$ export APPENGINE_SDK=/path/to/google_appengine
$ export PATH=$PATH:$APPENGINE_SDK

Before installing this library, you have to install appengine SDK. And copy appengine, appengine_internal and goprotobuf as followings :

$ export APPENGINE_SDK=/path/to/google_appengine
$ ln -s $APPENGINE_SDK/goroot/src/pkg/appengine
$ ln -s $APPENGINE_SDK/goroot/src/pkg/appengine_internal

There is some incompatibility between 1.7.5 and go 1.0.3. You can fix this by commenting out the following line in the file ${APPENGINE_SDK}/goroot/src/pkg/appengine_internal/api_dev.go:

func init() { os.DisableWritesForAppEngine = true }

It should be:

//func init() { os.DisableWritesForAppEngine = true }

This library can be installed as following :

$ go get github.com/icub3d/appenginetesting

Usage

The documentation has some basic examples. You can also find complete test examples within gorca/(*_test.go). Finally, context_test.go and recorder_test.go show an example of usage.

Documentation

Overview

Package appenginetesting provides an appengine.Context for testing.

Index

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

func NewContext(opts *Options) (*Context, error)

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) AppID

func (c *Context) AppID() string

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) Criticalf

func (c *Context) Criticalf(format string, args ...interface{})

func (*Context) Debugf

func (c *Context) Debugf(format string, args ...interface{})

func (*Context) Errorf

func (c *Context) Errorf(format string, args ...interface{})

func (*Context) FullyQualifiedAppID

func (c *Context) FullyQualifiedAppID() string

func (*Context) Infof

func (c *Context) Infof(format string, args ...interface{})

func (*Context) Login

func (c *Context) Login(email string, admin bool)

func (*Context) Logout

func (c *Context) Logout()

func (*Context) Request

func (c *Context) Request() interface{}

func (*Context) Warningf

func (c *Context) Warningf(format string, args ...interface{})

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

func (*ContextRecorder) Creator

func (r *ContextRecorder) Creator() func(r *http.Request) appengine.Context

type Options

type Options struct {
	// AppId to pretend to be. By default, "testapp"
	AppId string
}

Options control optional behavior for NewContext.

Jump to

Keyboard shortcuts

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