Skip to content

Commit

Permalink
Merge pull request #15 from twharmon/Add-fakes-package-level-document…
Browse files Browse the repository at this point in the history
…ation

Add fakes package level documentation
  • Loading branch information
twharmon authored Apr 12, 2022
2 parents 53a9e01 + 8bdc58a commit a2cec03
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions fakes/context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
// 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)
// }
// }
package fakes

import (
Expand All @@ -6,12 +34,15 @@ import (
"github.com/twharmon/golamb"
)

// Context implements the golamb.Context interface.
type Context struct {
request *Request
response *Response
aws *AWS
}

// NewContext creates a value that implements the golamb.Context
// interface.
func NewContext() *Context {
return &Context{
request: NewRequest(),
Expand All @@ -20,14 +51,17 @@ func NewContext() *Context {
}
}

// Request implements the golamb.Context interface.
func (c *Context) Request() golamb.Request {
return c.request
}

// AWS implements the golamb.Context interface.
func (c *Context) AWS() golamb.AWSServiceProvider {
return c.aws
}

// Response implements the golamb.Context interface.
func (c *Context) Response(status int, body ...interface{}) golamb.Responder {
c.response.response.StatusCode = status
if len(body) > 0 {
Expand All @@ -40,49 +74,54 @@ func (c *Context) Response(status int, body ...interface{}) golamb.Responder {
return c.response
}

// WithRequest sets the request of the fake Context.
func (c *Context) WithRequest(r *Request) *Context {
c.request = r
return c
}

// WithAWS sets the AWS service provider of the fake Context.
func (c *Context) WithAWS(a *AWS) *Context {
c.aws = a
return c
}

func (c *Context) WithResponse(r *Response) *Context {
c.response = r
return c
}

// LogDebug implements the golamb.Context interface.
func (c *Context) LogDebug(message string, args ...interface{}) {

}

// LogInfo implements the golamb.Context interface.
func (c *Context) LogInfo(message string, args ...interface{}) {

}

// LogNotice implements the golamb.Context interface.
func (c *Context) LogNotice(message string, args ...interface{}) {

}

// LogWarning implements the golamb.Context interface.
func (c *Context) LogWarning(message string, args ...interface{}) {

}

// LogError implements the golamb.Context interface.
func (c *Context) LogError(message string, args ...interface{}) {

}

// LogCritical implements the golamb.Context interface.
func (c *Context) LogCritical(message string, args ...interface{}) {

}

// LogAlert implements the golamb.Context interface.
func (c *Context) LogAlert(message string, args ...interface{}) {

}

// LogEmergency implements the golamb.Context interface.
func (c *Context) LogEmergency(message string, args ...interface{}) {

}

0 comments on commit a2cec03

Please sign in to comment.