fakes

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 10 Imported by: 0

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

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

func (a *AWS) S3() s3iface.S3API

S3 implements the golamb.AWSServiceProvider interface.

func (*AWS) SES

func (a *AWS) SES() sesiface.SESAPI

SES implements the golamb.AWSServiceProvider interface.

func (*AWS) SFN added in v0.1.8

func (a *AWS) SFN() sfniface.SFNAPI

SFN implements the golamb.AWSServiceProvider interface.

func (*AWS) SSM

func (a *AWS) SSM() ssmiface.SSMAPI

SSM implements the golamb.AWSServiceProvider interface.

func (*AWS) STS

func (a *AWS) STS() stsiface.STSAPI

STS implements the golamb.AWSServiceProvider interface.

func (*AWS) WithDynamoDB

func (a *AWS) WithDynamoDB(svc dynamodbiface.DynamoDBAPI) *AWS

WithDynamoDB sets the dynamodb client of the AWSServiceProvider.

func (*AWS) WithS3

func (a *AWS) WithS3(svc s3iface.S3API) *AWS

WithS3 sets the s3 client of the AWSServiceProvider.

func (*AWS) WithSES

func (a *AWS) WithSES(svc sesiface.SESAPI) *AWS

WithSES sets the ses client of the AWSServiceProvider.

func (*AWS) WithSFN added in v0.1.8

func (a *AWS) WithSFN(svc sfniface.SFNAPI) *AWS

WithSFN sets the sfn client of the AWSServiceProvider.

func (*AWS) WithSSM

func (a *AWS) WithSSM(svc ssmiface.SSMAPI) *AWS

WithSSM sets the ssm client of the AWSServiceProvider.

func (*AWS) WithSTS

func (a *AWS) WithSTS(svc stsiface.STSAPI) *AWS

WithSTS sets the sts 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) LogAlert

func (c *Context) LogAlert(message string, args ...any)

LogAlert implements the golamb.Context interface.

func (*Context) LogCritical

func (c *Context) LogCritical(message string, args ...any)

LogCritical implements the golamb.Context interface.

func (*Context) LogDebug

func (c *Context) LogDebug(message string, args ...any)

LogDebug implements the golamb.Context interface.

func (*Context) LogEmergency

func (c *Context) LogEmergency(message string, args ...any)

LogEmergency implements the golamb.Context interface.

func (*Context) LogError

func (c *Context) LogError(message string, args ...any)

LogError implements the golamb.Context interface.

func (*Context) LogInfo

func (c *Context) LogInfo(message string, args ...any)

LogInfo implements the golamb.Context interface.

func (*Context) LogNotice

func (c *Context) LogNotice(message string, args ...any)

LogNotice implements the golamb.Context interface.

func (*Context) LogWarning

func (c *Context) LogWarning(message string, args ...any)

LogWarning implements the golamb.Context interface.

func (*Context) Request

func (c *Context) Request() golamb.Request

Request implements the golamb.Context interface.

func (*Context) Response

func (c *Context) Response(status int, body ...any) golamb.Responder

Response implements the golamb.Context interface.

func (*Context) WithRequest

func (c *Context) WithRequest(r *Request) *Context

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

func (r *Request) Body(v any) error

Body implements the golamb.Request interface.

func (*Request) Cookie

func (r *Request) Cookie(key string) *http.Cookie

Cookie implements the golamb.Request interface.

func (*Request) Header

func (r *Request) Header(key string) string

Header implements the golamb.Request interface.

func (*Request) Headers

func (r *Request) Headers() map[string]string

Headers implements the golamb.Request interface.

func (*Request) Path

func (r *Request) Path(key string) string

Path implements the golamb.Request interface.

func (*Request) Query

func (r *Request) Query(key string) string

Query implements the golamb.Request interface.

func (*Request) RawPath

func (r *Request) RawPath() string

RawPath implements the golamb.Request interface.

func (*Request) WithBody

func (r *Request) WithBody(v any) error

WithBody sets the body of the fake Request.

func (*Request) WithCookies

func (r *Request) WithCookies(cookie map[string]*http.Cookie) *Request

WithCookies sets the cookies of the fake Request.

func (*Request) WithHeaders

func (r *Request) WithHeaders(header map[string]string) *Request

WithHeaders sets the headers of the fake Request.

func (*Request) WithPath

func (r *Request) WithPath(path map[string]string) *Request

WithPath sets the path parameters of the fake Request.

func (*Request) WithQuery

func (r *Request) WithQuery(query map[string]string) *Request

WithQuery sets the query parameters of the fake Request.

func (*Request) WithRawPath

func (r *Request) WithRawPath(rawPath string) *Request

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.

func (*Response) SetCookie added in v0.1.1

func (r *Response) SetCookie(cookie *http.Cookie) golamb.Responder

SetCookie implements the golamb.Responder interface.

func (*Response) SetHeader added in v0.1.1

func (r *Response) SetHeader(key string, val string) golamb.Responder

SetHeader implements the golamb.Responder interface.

Jump to

Keyboard shortcuts

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