Documentation ¶
Overview ¶
Package fakes provides a way to fake or stub Context, Request, Response, and AWSServiceProvider. This makes it easier to test your lambda handler functions.
Example:
package main func handler(c golamb.Context) golamb.Responder { foo := c.Request().Query("foo") body := map[string]string{"foo": foo} return c.Response(200, body) } func main() { golamb.Start(handler) } func TestHandler(t *testing.T) { req := fakes.NewRequest().WithQuery(map[string]string{"foo": "bar"}) ctx := fakes.NewContext().WithRequest(req) resp, err := handler(ctx).Respond() if err != nil { t.Fatalf("unexpected err: %s", err) } if resp.Body != `{"foo":"bar"}` { t.Fatalf("incorrect response: %v", resp) } }
Index ¶
- type AWS
- func (a *AWS) DynamoDB() dynamodbiface.DynamoDBAPI
- func (a *AWS) S3() s3iface.S3API
- func (a *AWS) SES() sesiface.SESAPI
- func (a *AWS) SFN() sfniface.SFNAPI
- func (a *AWS) SSM() ssmiface.SSMAPI
- func (a *AWS) STS() stsiface.STSAPI
- func (a *AWS) WithDynamoDB(svc dynamodbiface.DynamoDBAPI) *AWS
- func (a *AWS) WithS3(svc s3iface.S3API) *AWS
- func (a *AWS) WithSES(svc sesiface.SESAPI) *AWS
- func (a *AWS) WithSFN(svc sfniface.SFNAPI) *AWS
- func (a *AWS) WithSSM(svc ssmiface.SSMAPI) *AWS
- func (a *AWS) WithSTS(svc stsiface.STSAPI) *AWS
- type Context
- func (c *Context) LogAlert(message string, args ...any)
- func (c *Context) LogCritical(message string, args ...any)
- func (c *Context) LogDebug(message string, args ...any)
- func (c *Context) LogEmergency(message string, args ...any)
- func (c *Context) LogError(message string, args ...any)
- func (c *Context) LogInfo(message string, args ...any)
- func (c *Context) LogNotice(message string, args ...any)
- func (c *Context) LogWarning(message string, args ...any)
- func (c *Context) Request() golamb.Request
- func (c *Context) Response(status int, body ...any) golamb.Responder
- func (c *Context) WithRequest(r *Request) *Context
- type Request
- func (r *Request) Body(v any) error
- func (r *Request) Cookie(key string) *http.Cookie
- func (r *Request) Header(key string) string
- func (r *Request) Headers() map[string]string
- func (r *Request) Path(key string) string
- func (r *Request) Query(key string) string
- func (r *Request) RawPath() string
- func (r *Request) WithBody(v any) error
- func (r *Request) WithCookies(cookie map[string]*http.Cookie) *Request
- func (r *Request) WithHeaders(header map[string]string) *Request
- func (r *Request) WithPath(path map[string]string) *Request
- func (r *Request) WithQuery(query map[string]string) *Request
- func (r *Request) WithRawPath(rawPath string) *Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWS ¶
type AWS struct {
// contains filtered or unexported fields
}
AWS implements the golamb.AWSServiceProvider interface.
func NewAWS ¶
func NewAWS() *AWS
NewAWS creates a value that implements the golamb.AWSServiceProvider interface.
func (*AWS) DynamoDB ¶
func (a *AWS) DynamoDB() dynamodbiface.DynamoDBAPI
DynamoDB implements the golamb.AWSServiceProvider interface.
func (*AWS) WithDynamoDB ¶
func (a *AWS) WithDynamoDB(svc dynamodbiface.DynamoDBAPI) *AWS
WithDynamoDB sets the dynamodb client of the AWSServiceProvider.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context implements the golamb.Context interface.
func NewContext ¶
func NewContext() *Context
NewContext creates a value that implements the golamb.Context interface.
func (*Context) LogCritical ¶
LogCritical implements the golamb.Context interface.
func (*Context) LogEmergency ¶
LogEmergency implements the golamb.Context interface.
func (*Context) LogWarning ¶
LogWarning implements the golamb.Context interface.
func (*Context) WithRequest ¶
WithRequest sets the request of the fake Context.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request implements the golamb.Request interface.
func NewRequest ¶
func NewRequest() *Request
NewRequest creates a value that implements the golamb.Request interface.
func (*Request) WithCookies ¶
WithCookies sets the cookies of the fake Request.
func (*Request) WithHeaders ¶
WithHeaders sets the headers of the fake Request.
func (*Request) WithRawPath ¶
WithRawPath sets the raw path of the fake Request.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response implements the golamb.Responder interface.
func NewResponse ¶
func NewResponse() *Response
NewResponse creates a value that implements the golamb.Responder interface.
func (*Response) Respond ¶
func (r *Response) Respond() (*events.APIGatewayV2HTTPResponse, error)
Response implements the golamb.Responder interface.