Documentation
¶
Overview ¶
Package test generates request contexts suitable for use in unit tests.
Package test provides support for testing Ori handlers.
Index ¶
- func ConsumableJWT(claimSet *jws.ClaimSet, secret string, uses int) string
- func JWT(claimSet *jws.ClaimSet, secret string) string
- func LoadConfig(ctx context.Context, conf interface{}) error
- func MustEncodeJSON(obj interface{}) *bytes.Buffer
- func WithAuthorizedAccount(ctx context.Context, authorizedAccount interface{}) context.Context
- func WithConfig(ctx context.Context, conf map[string]interface{}) context.Context
- type HandlerState
- func (s *HandlerState) Account(a *account.Account) *HandlerState
- func (s *HandlerState) Body(b interface{}) *HandlerState
- func (s *HandlerState) Config(c interface{}) *HandlerState
- func (s *HandlerState) Param(key, value string) *HandlerState
- func (s *HandlerState) Run(ctx context.Context, handler kami.HandlerFunc) *httptest.ResponseRecorder
- func (s *HandlerState) Scope(scope string) *HandlerState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumableJWT ¶
ConsumableJWT generates a consumable JWT from claimset and secret, with u uses available. It panics if it encounters an error.
func LoadConfig ¶
LoadConfig retrieves the most recent state of the configuration from the datastore into the value pointed to by conf.
func MustEncodeJSON ¶
MustEncodeJSON converts obj into JSON data using json.Marshal. It panics if json.Marshal returns an error.
func WithAuthorizedAccount ¶
WithAuthorizedAccount returns a new context.Context based on ctx with the supplied account associated with it.
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 (*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 ¶
func (s *HandlerState) Run(ctx context.Context, handler kami.HandlerFunc) *httptest.ResponseRecorder
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.