Skip to content

Commit 6bd3d3c

Browse files
author
Emil Pirfält
committed
Fix test which broke and add new once
1 parent dc7e235 commit 6bd3d3c

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

handlerfunc/adapter.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import (
99

1010
type HandlerFuncAdapter struct {
1111
core.RequestAccessor
12-
handlerFunc http.Handler
12+
handler http.Handler
1313
}
1414

15-
func New(handler http.Handler) *HandlerFuncAdapter {
15+
func New(handlerFunc http.HandlerFunc) *HandlerFuncAdapter {
1616
return &HandlerFuncAdapter{
17-
handlerFunc: handler,
17+
handler: handlerFunc,
18+
}
19+
}
20+
21+
func NewHandler(handler http.Handler) *HandlerFuncAdapter {
22+
return &HandlerFuncAdapter{
23+
handler: handler,
1824
}
1925
}
2026

@@ -25,7 +31,7 @@ func (h *HandlerFuncAdapter) Proxy(event events.APIGatewayProxyRequest) (events.
2531
}
2632

2733
w := core.NewProxyResponseWriter()
28-
h.handlerFunc.ServeHTTP(http.ResponseWriter(w), req)
34+
h.handler.ServeHTTP(http.ResponseWriter(w), req)
2935

3036
resp, err := w.GetProxyResponse()
3137
if err != nil {

handlerfunc/adapter_test.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,42 @@ import (
1212
. "github.com/onsi/gomega"
1313
)
1414

15+
type handler struct{}
16+
17+
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
18+
w.Header().Add("unfortunately-required-header", "")
19+
fmt.Fprintf(w, "Go Lambda!!")
20+
}
21+
1522
var _ = Describe("HandlerFuncAdapter tests", func() {
16-
Context("Simple ping request", func() {
23+
Context("Simple ping request, HandlerFunc", func() {
1724
It("Proxies the event correctly", func() {
1825
log.Println("Starting test")
1926

20-
handler := func(w http.ResponseWriter, req *http.Request) {
27+
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
2128
w.Header().Add("unfortunately-required-header", "")
2229
fmt.Fprintf(w, "Go Lambda!!")
2330
}
2431

25-
adapter := handlerfunc.New(handler)
32+
adapter := handlerfunc.New(handlerFunc)
33+
34+
req := events.APIGatewayProxyRequest{
35+
Path: "/ping",
36+
HTTPMethod: "GET",
37+
}
38+
39+
resp, err := adapter.Proxy(req)
40+
41+
Expect(err).To(BeNil())
42+
Expect(resp.StatusCode).To(Equal(200))
43+
})
44+
})
45+
46+
Context("Simple ping request, Handler", func() {
47+
It("Proxies the event correctly", func() {
48+
log.Println("Starting test")
49+
50+
adapter := handlerfunc.NewHandler(handler{})
2651

2752
req := events.APIGatewayProxyRequest{
2853
Path: "/ping",

0 commit comments

Comments
 (0)