|
| 1 | +package gorillamux_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + "github.com/aws/aws-lambda-go/events" |
| 9 | + "github.com/awslabs/aws-lambda-go-api-proxy/gorillamux" |
| 10 | + "github.com/gorilla/mux" |
| 11 | + |
| 12 | + . "github.com/onsi/ginkgo" |
| 13 | + . "github.com/onsi/gomega" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = Describe("GorillaMuxAdapter tests", func() { |
| 17 | + Context("Simple ping request", func() { |
| 18 | + It("Proxies the event correctly", func() { |
| 19 | + log.Println("Starting test") |
| 20 | + |
| 21 | + homeHandler := func(w http.ResponseWriter, req *http.Request) { |
| 22 | + w.Header().Add("unfortunately-required-header", "") |
| 23 | + fmt.Fprintf(w, "Home Page") |
| 24 | + } |
| 25 | + |
| 26 | + productsHandler := func(w http.ResponseWriter, req *http.Request) { |
| 27 | + w.Header().Add("unfortunately-required-header", "") |
| 28 | + fmt.Fprintf(w, "Products Page") |
| 29 | + } |
| 30 | + |
| 31 | + r := mux.NewRouter() |
| 32 | + r.HandleFunc("/", homeHandler) |
| 33 | + r.HandleFunc("/products", productsHandler) |
| 34 | + |
| 35 | + adapter := gorillamux.New(r) |
| 36 | + |
| 37 | + homePageReq := events.APIGatewayProxyRequest{ |
| 38 | + Path: "/", |
| 39 | + HTTPMethod: "GET", |
| 40 | + } |
| 41 | + |
| 42 | + homePageResp, homePageReqErr := adapter.Proxy(homePageReq) |
| 43 | + |
| 44 | + Expect(homePageReqErr).To(BeNil()) |
| 45 | + Expect(homePageResp.StatusCode).To(Equal(200)) |
| 46 | + Expect(homePageResp.Body).To(Equal("Home Page")) |
| 47 | + |
| 48 | + productsPageReq := events.APIGatewayProxyRequest{ |
| 49 | + Path: "/products", |
| 50 | + HTTPMethod: "GET", |
| 51 | + } |
| 52 | + |
| 53 | + productsPageResp, productsPageReqErr := adapter.Proxy(productsPageReq) |
| 54 | + |
| 55 | + Expect(productsPageReqErr).To(BeNil()) |
| 56 | + Expect(productsPageResp.StatusCode).To(Equal(200)) |
| 57 | + Expect(productsPageResp.Body).To(Equal("Products Page")) |
| 58 | + }) |
| 59 | + }) |
| 60 | +}) |
0 commit comments