forked from awslabs/aws-lambda-go-api-proxy
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadapter_test.go
51 lines (38 loc) · 1.15 KB
/
adapter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package httpadapter_test
import (
"context"
"fmt"
"log"
"net/http"
"github.com/LF-Engineering/aws-lambda-go-api-proxy/httpadapter"
"github.com/aws/aws-lambda-go/events"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type handler struct{}
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Add("unfortunately-required-header", "")
fmt.Fprintf(w, "Go Lambda!!")
}
var _ = Describe("HTTPAdapter tests", func() {
Context("Simple ping request", func() {
It("Proxies the event correctly", func() {
log.Println("Starting test")
var httpHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("unfortunately-required-header", "")
fmt.Fprintf(w, "Go Lambda!!")
})
adapter := httpadapter.New(httpHandler)
req := events.APIGatewayProxyRequest{
Path: "/ping",
HTTPMethod: "GET",
}
resp, err := adapter.ProxyWithContext(context.Background(), req)
Expect(err).To(BeNil())
Expect(resp.StatusCode).To(Equal(200))
resp, err = adapter.Proxy(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode).To(Equal(200))
})
})
})