test

package
v0.0.0-...-b405234 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package test generates request contexts suitable for use in unit tests.

Package test provides support for testing Ori handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumableJWT

func ConsumableJWT(claimSet *jws.ClaimSet, secret string, uses int) string

ConsumableJWT generates a consumable JWT from claimset and secret, with u uses available. It panics if it encounters an error.

func JWT

func JWT(claimSet *jws.ClaimSet, secret string) string

JWT generates a JWT from claimSet and secret. It panics if it encounters an error.

func LoadConfig

func LoadConfig(ctx context.Context, conf interface{}) error

LoadConfig retrieves the most recent state of the configuration from the datastore into the value pointed to by conf.

func MustEncodeJSON

func MustEncodeJSON(obj interface{}) *bytes.Buffer

MustEncodeJSON converts obj into JSON data using json.Marshal. It panics if json.Marshal returns an error.

func WithAuthorizedAccount

func WithAuthorizedAccount(ctx context.Context, authorizedAccount interface{}) context.Context

WithAuthorizedAccount returns a new context.Context based on ctx with the supplied account associated with it.

func WithConfig

func WithConfig(ctx context.Context, conf map[string]interface{}) context.Context

WithConfig returns a new context.Context based on ctx with the supplied configuration variables set.

Types

type HandlerState

type HandlerState struct {
	// contains filtered or unexported fields
}

HandlerState represents the complete set of application state underlying a route handler. It includes the body to be serialized to JSON for the request, the application configuration, the authenticated account, and the route parameters that underlay the invocation.

func NewState

func NewState() *HandlerState

NewState creates a new HandlerState.

func (*HandlerState) Account

func (s *HandlerState) Account(a *account.Account) *HandlerState

Account sets the authenticated account for the handler test to a.

func (*HandlerState) Body

func (s *HandlerState) Body(b interface{}) *HandlerState

Body sets an object to be serialized using json.Marshal to produce the request body for the handler test.

func (*HandlerState) Config

func (s *HandlerState) Config(c interface{}) *HandlerState

Config sets the configuration state of the application for the handler test to c, which can be any value that App Engine Datastore can process (see the documentation there for more information). For example:

s.Config(&struct{Name string}{"Jiminy Cricket"})

func (*HandlerState) Param

func (s *HandlerState) Param(key, value string) *HandlerState

Param sets the value of the route param for the handler test. In your handler, if you ask for the value of a route param:

rest.Param(ctx, "superheroId", "Batwoman")

ordinarily, the value for this would be supplied from Kami. In the test environment, Kami is out of the loop, so to vary the values resulting from rest.Param, you set them using Param.

func (*HandlerState) Run

Run invokes handler with ctx. It returns an *httptest.ResponseRecorder containing the result of the invocation.

func (*HandlerState) Scope

func (s *HandlerState) Scope(scope string) *HandlerState

Scope sets the handler test's authentication scope (i.e., what the auth token says the request is allowed to do) to scope. This should be a comma-delimited string if you want to set multiple scopes.

Jump to

Keyboard shortcuts

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